美文网首页
《vue》router.push,params不生效问题

《vue》router.push,params不生效问题

作者: BA_凌晨四点 | 来源:发表于2021-07-29 17:38 被阅读0次

情况1:

使用 push,跳转不能使用path,而是name

this.$router.push({
  name: 'test', // 这里不能是: path: '/test'
  query: { a: 123 }
})

情况2:

beforeEach这个钩子函数中不能获取 params以及query等!!!

所以一般在computed中拿 params:

computed: {
    myParams() {
      return this.$route.params;
    }
},
created() {
  console.log(this.myParams);
}

相关文章

网友评论

      本文标题:《vue》router.push,params不生效问题

      本文链接:https://www.haomeiwen.com/subject/dlkfvltx.html