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中没带参数))


版权声明:本文为qq_43436117原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。