login() {
if(this.email.length > 0 && this.password.length >0) {
this.$http.post('/api/login', {
user: this.email,
password: this.password
})
.then(res => {
let userPwd = res.data
if(this.password == userPwd) {
this.$router.push("/")
} else {
alert("錯(cuò)誤,請(qǐng)重新輸入!")
}
})
.catch(err => {
console.log(err)
})
} else {
alert("輸入錯(cuò)誤!")
}
}
this.$router.push("/") does not jump to the homepage, but becomes like this: http://127.0.0.1:8080/login?email=yejia@qq.com&password=123456
, what's wrong?
The this point you have here is no longer the object of vue, you can change it like this
login() {
const that = this;
if(this.email.length > 0 && this.password.length >0) {
this.$http.post('/api/login', {
user: this.email,
password: this.password
})
.then(res => {
let userPwd = res.data
if(this.password == userPwd) {
that.$router.push("/")
} else {
alert("錯(cuò)誤,請(qǐng)重新輸入!")
}
})
.catch(err => {
console.log(err)
})
} else {
alert("輸入錯(cuò)誤!")
}
}
Is it possible that it has jumped, but the homepage judged that you are not logged in, and then jumped back.