关于vue router 传参获取不到(接受param为unde

2020-06-19  本文已影响0人  Poppy11

在当前路由中有一个toArticle方法可以跳转到article页面

  methods:{
      toArticle:function(index) {
      this.$router.push({path:'/article',params:this.blogList[index]});
    }
  }

在article中接受不到params

mounted(){
  console.log(this.$route.params)
  //这里输出undifined
}

导致这样的原因是因为params需要通过name来获取,这里就要明白query和params的区别了

query要用path来引入,接收参数都是this.$route.query.name。query类似于ajax中get传参,即在浏览器地址栏中显示参数。

params要用name来引入,接收参数都是this.$route.params.name。params则类似于post,即在浏览器地址栏中不显示参数。

所以以上带面做下面这样的修改就可以获取数据:

  methods:{
      toArticle:function(index) {
      this.$router.push({name:'article',params:this.blogList[index]});
    }
  }
上一篇 下一篇

猜你喜欢

热点阅读