I created a login component
router
export default new Router({
mode : "history",
routes: [
{
path: "/login",
name: "login",
component: login
},
{
path: "/test",
name: "test",
component : app
}
]
})```
url http://localhost:8080/login
< template >
<input type="text" class="form-control" placeholder="user" v-model="name">
<input type="password" class="form-control" placeholder="password" v-model="password">
<input type="submit" class="btn btn-primary " @click="login" >
< / div >
< / template >
< script >
export default {
data(){
return{
password:"",
name:""
}
},
methods:{
login(){
const self = this;
this.$axios({
method:"post",
url:"/api/login",
data : {
name : this.name,
password: this.password
}
}).then(response =>{
console.log("response" + response.data)
if (response ==="0")
console.log("wrong user")
else if(response === "1")
console.log("wrong pwd")
else if (response === "2"){
self.$router.replace("/test");
console.log("OK")
}
})
}
}
}
response === 2
this.$router.push("/test/");
url