vue.js - 无法引用路由器
vue.js - Unable to reference router
在编辑我的代码之间的某个时刻,我至少有一部分工作,但当然在那之前没有提交。
项目:https://github.com/Ampix0/ticker-for-robinhood;
在第 26 行你可以看到登录功能,当它完成时应该路由到下一个页面,传递访问令牌。
错误
TypeError: Cannot read property '$router' of undefined
at eval (eval at <anonymous> (renderer.js:1574), <anonymous>:18:21)
基本上是我前几天刚回答的同一个问题:
因为您在 .then(function (response) {..
中丢失了 this
引用
使用箭头函数可以轻松解决这个问题:
.then((response) => {
this.$router.push({
name: 'home-page',
params: {
authKey: response.data.token
}
})
})
在编辑我的代码之间的某个时刻,我至少有一部分工作,但当然在那之前没有提交。
项目:https://github.com/Ampix0/ticker-for-robinhood;
在第 26 行你可以看到登录功能,当它完成时应该路由到下一个页面,传递访问令牌。
错误
TypeError: Cannot read property '$router' of undefined
at eval (eval at <anonymous> (renderer.js:1574), <anonymous>:18:21)
基本上是我前几天刚回答的同一个问题:
因为您在 .then(function (response) {..
this
引用
使用箭头函数可以轻松解决这个问题:
.then((response) => {
this.$router.push({
name: 'home-page',
params: {
authKey: response.data.token
}
})
})