【Vue】【Router】手动跳转用 this.$router.push() 时 $router 未定义的问题
生活随笔
收集整理的這篇文章主要介紹了
【Vue】【Router】手动跳转用 this.$router.push() 时 $router 未定义的问题
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
初入Vue,手寫(xiě)路由跳轉(zhuǎn)時(shí)的問(wèn)題:
?
toXxxRoute: () => {this.$router.push({'path': '/xxx', 'name': 'xxx'}) }由于使用了箭頭函數(shù),this的指向與傳統(tǒng) js 里不同
所以報(bào)錯(cuò)
TypeError: Cannot read property '$router' of undefined?
與其保持一個(gè)this變量,不如改回寫(xiě) function 的方式
toXxxRoute: function(){this.$router.push({'path': '/xxx', 'name': 'xxx'}) }?
轉(zhuǎn)載于:https://www.cnblogs.com/CoderMonkie/p/vue-router-undefined.html
總結(jié)
以上是生活随笔為你收集整理的【Vue】【Router】手动跳转用 this.$router.push() 时 $router 未定义的问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 大数据技术原理与应用学习笔记(一)
- 下一篇: elementui el-from 怎样