this.$route.query和this.$route.params的正确使用

1.this.$route.query的使用

(1)、传参数:

this.$router.push({
         path: '/checkout',
         query:{
               productId:id,
          }
}

(2)、获取参数:

this.$route.query.productId

(3)、在url中形式(url中带参数)

http://xxx/#/goodsDetails?productId=150642571432849

(4)、页面之间用路由跳转传参时,刷新跳转后传参的页面,数据还会显示存在(项目中遇到此问题)

2.this.$route.params的使用

(1)、传参数:

// An highlighted block
this.$router.push({
         name: 'checkout',
         params:{
               productId:id,
          }
};

(2)、获取参数:

// An highlighted block
this.$route.params.productId

(3)、在url中形式(url中不带参数)

// An highlighted block
http://172.19.186.224:8080/#/checkout

(4)、页面之间用路由跳转传参时,刷新跳转后传参的页面,数据不存在((url中没带参数))

  • 14
    点赞
  • 65
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值