vue传参之params传参query传参

 

vue编程式导航,在这里我们必须要明白一个知识点,就是params和query传参的用法。

 

params传参,路径不能使用path,只能使用name,不然取不到传的数据。

this.$router.push({name:'Good',params:{goodsId:id}})

取数据时用params获取

this.$route.params.goodsId

 

query传参,用的是path,而不是name,否则也会出错。

this.$router.push({path:'/Good',query:{goodsId:id}})

取数据使用query

this.$route.query.goodsId

 

如果使用了以上两种传参方式,使用时我们可以做一下兼容处理

this.goodsId= this.$route.query.goodsId ? this.$route.query.goodsId:this.$route.params.goodsId

 

 

 

 

 

你可能感兴趣的:(vue,vue传参,query,params)