【Vue】【Router】手动跳转用 this.$router.push() 时 $router 未定义的问题
生活随笔
收集整理的這篇文章主要介紹了
【Vue】【Router】手动跳转用 this.$router.push() 时 $router 未定义的问题
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
初入Vue,手寫路由跳轉時的問題:
?
toXxxRoute: () => {this.$router.push({'path': '/xxx', 'name': 'xxx'}) }由于使用了箭頭函數,this的指向與傳統 js 里不同
所以報錯
TypeError: Cannot read property '$router' of undefined?
與其保持一個this變量,不如改回寫 function 的方式
toXxxRoute: function(){this.$router.push({'path': '/xxx', 'name': 'xxx'}) }?
轉載于:https://www.cnblogs.com/CoderMonkie/p/vue-router-undefined.html
總結
以上是生活随笔為你收集整理的【Vue】【Router】手动跳转用 this.$router.push() 时 $router 未定义的问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 大数据技术原理与应用学习笔记(一)
- 下一篇: mysql 指定账户已存在_安装mysq