vue传参之params传参query传参

我就是我 2021-09-16 02:42 812阅读 0赞

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

发表评论

表情:
评论列表 (有 0 条评论,812人围观)

还没有评论,来说两句吧...

相关阅读

    相关 vue

    一、非文件上传: @RequseParam与@RequestBody接收参数,前端传参,params传给@RequseParam,data传给@RequestBody 1、