如下所示:
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("錯誤,請重新輸入!") } }) .catch(err => { console.log(err) }) } else { alert("輸入錯誤!") } }this.$router.push(“/”)不是跳轉到主頁,而是變成這樣:http://127.0.0.1:8080/login?email=yejia%40qq.com&password=123456,請問哪里錯啦?
解決方案1:
有沒有可能是已經跳轉了,但是主頁判斷成了沒有登錄,然后又跳回來了。
解決方案2:
你這里的 this指向已經不是 vue 的對象啦,可以這么改
login() { const self = 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) { self.$router.push("/") } else { alert("錯誤,請重新輸入!") } }) .catch(err => { console.log(err) }) } else { alert("輸入錯誤!") } }以上這篇解決vue.js this.$router.push無效的問題就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林網。
新聞熱點
疑難解答