【问题标题】:wierd bug with vuejs 2 routervue js 2路由器的奇怪错误
【发布时间】: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


【解决方案1】:

我应该使用 self.$router.push 而不是 router.push

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-22
    • 2020-06-28
    • 2017-02-21
    • 2013-05-20
    • 2017-08-03
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    相关资源
    最近更新 更多