您好,登錄后才能下訂單哦!
這篇文章主要介紹了怎么解決vue.js this.$router.push無(wú)效的問(wèn)題,具有一定借鑒價(jià)值,感興趣的朋友可以參考下,希望大家閱讀完這篇文章之后大有收獲,下面讓小編帶著大家一起了解一下。
如下所示:
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(“/”)不是跳轉(zhuǎn)到主頁(yè),而是變成這樣:http://127.0.0.1:8080/login?email=yejia%40qq.com&password=123456,請(qǐng)問(wèn)哪里錯(cuò)啦?
解決方案1:
有沒有可能是已經(jīng)跳轉(zhuǎn)了,但是主頁(yè)判斷成了沒有登錄,然后又跳回來(lái)了。
解決方案2:
你這里的 this指向已經(jīng)不是 vue 的對(duì)象啦,可以這么改
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("錯(cuò)誤,請(qǐng)重新輸入!") } }) .catch(err => { console.log(err) }) } else { alert("輸入錯(cuò)誤!") } }
感謝你能夠認(rèn)真閱讀完這篇文章,希望小編分享的“怎么解決vue.js this.$router.push無(wú)效的問(wèn)題”這篇文章對(duì)大家有幫助,同時(shí)也希望大家多多支持億速云,關(guān)注億速云行業(yè)資訊頻道,更多相關(guān)知識(shí)等著你來(lái)學(xué)習(xí)!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。