国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > JavaScript > 正文

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

2019-11-19 13:03:26
字體:
來源:轉載
供稿:網友

如下所示:

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無效的問題就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持武林網。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永修县| 苏尼特左旗| 延边| 新田县| 常宁市| 九龙县| 天峻县| 张掖市| 三都| 库伦旗| 贡嘎县| 独山县| 宜黄县| 江城| 中牟县| 潍坊市| 古丈县| 平罗县| 保亭| 浦东新区| 峡江县| 扶沟县| 兖州市| 云龙县| 商南县| 兴文县| 汝阳县| 额尔古纳市| 巴林右旗| 逊克县| 和田市| 牡丹江市| 雅江县| 张掖市| 冀州市| 鹿邑县| 宁都县| 金寨县| 太湖县| 瓦房店市| 安泽县|