亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

解決vue.js this.$router.push無效的問題

 更新時(shí)間:2018年09月03日 15:31:29   作者:gang456789  
今天小編就為大家分享一篇解決vue.js this.$router.push無效的問題,具有很好的參考價(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ò)誤,請重新輸入!")
    }
   })
   .catch(err => {
    console.log(err)
   })
  } else {
   alert("輸入錯(cuò)誤!")
  }
  }

this.$router.push(“/”)不是跳轉(zhuǎn)到主頁,而是變成這樣:http://127.0.0.1:8080/login?email=yejia%40qq.com&password=123456,請問哪里錯(cuò)啦?

解決方案1:

有沒有可能是已經(jīng)跳轉(zhuǎn)了,但是主頁判斷成了沒有登錄,然后又跳回來了。

解決方案2:

你這里的 this指向已經(jīng)不是 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("錯(cuò)誤,請重新輸入!")
   }
  })
  .catch(err => {
   console.log(err)
  })
 } else {
  alert("輸入錯(cuò)誤!")
 }
 }

以上這篇解決vue.js this.$router.push無效的問題就是小編分享給大家的全部內(nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論