首页 > 其他 > 详细

vue之this.$router.query和this.$router.params的使用与区别

时间:2020-11-25 15:16:36      阅读:272      评论:0      收藏:0      [点我收藏+]

一  this.$router.query的使用:

router/index.js

 1     {
 2      path:‘/mtindex‘,
 3      component: mtindex,
 4      //添加路由
 5      children:[
 6        {
 7         path:‘:shopid‘,
 8         component:guessdetail
 9        }
10      ]     
11     },

2 传参数

1 this.$router.push({
2         path: ‘/mtindex/detail‘, query:{shopid: item.id}
3        });

3 获取参数

1 this.$route.query.shopid

4 url的表现形式(url中带有参数)

http://localhost:8080/#/mtindex/detail?shopid=1

this.$router.params的使用:

1 router/index.js

 1 {
 2      path:‘/mtindex‘,
 3      component: mtindex,
 4      //添加路由
 5      children:[
 6        {
 7         path:"/detail",
 8         name:‘detail‘,
 9         component:guessdetail
10        }
11      ]     
12 
13     },

2 传参数(params相对应的是name  query相对应的是path)

1 this.$router.push({
2         name: ‘detail‘, params:{shopid: item.id}、
3         });

3 获取参数

1 this.$route.params.shopid

4 url的表现形式(url中没有带参数)

http://localhost:8080/#/mtindex

 

vue之this.$router.query和this.$router.params的使用与区别

原文:https://www.cnblogs.com/doudou-song/p/14035977.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!