【发布时间】:2017-06-05 19:47:21
【问题描述】:
这是我的 axios 请求的一部分:
.then(function (response) {
self.forms.process = false;
if( response.data.redirect ){
console.log(123);
router.push( { name: response.data.redirect } );
}
})
.catch(function (error) {
console.log(error.response.data);
如果我删除 router.push- 没有错误。 但是使用 router.go 我在 console.log(error.response.data) 行出现错误:
- //这里是console.log在router.push之前打印123
- 未捕获(承诺中)类型错误:无法读取未定义的属性“数据”
我不明白如何修复这个错误
【问题讨论】:
-
router.go(n): "此方法采用单个整数作为参数,指示在历史堆栈中前进或后退的步数"。你想要router.push()。 router.vuejs.org/en/essentials/navigation.html -
我也尝试过 push,但得到了同样的错误。看起来那是路由器错误本身
-
错误并不总是有响应,所以你应该在你的
catch函数上做:if(error.response){ console.log(error.response.data } -
response中有什么内容? -
修复了这个错误,但路由器仍然无法工作。什么也没发生。
标签: javascript vue.js vuejs2 vue-router