作者也是初学者,对两者区别大致认为:
1、简单参数传递的实现可以用query比较方便简单,多参数建议使用params
2、query会把参数显示在浏览器地址栏的path后面,而params相当于隐式的
3、params的参数页面刷新会清空,这点一定要注意(已经被坑过了,解决办法☞https://blog.csdn.net/xiaolegeaizy/article/details/105859162)
两者在使用的方法上也有不通:
this.$route.query的使用
1、router/index.js
{
path:'/mtindex',
component: mtindex,
//添加路由
children:[
{
path:':shopid',
component:guessdetail
}
]},
2、传参数--query的时候push里面的参数是path和query
this.$router.push({
path: '/mtindex/detail', query:{shopid: item.id}});
3、获取参数
this.$route.query.shopid
4、url的表现形式(url中带有参数)
http://localhost:8080/#/mtindex/detail?shopid=1
this.$route.params
1、router/index.js
{
path:'/mtindex',
component: mtindex,
//添加路由
children:[
{
path:"/detail",
name:'detail',
component:guessdetail
}
]},
2、传参数( params相对应的是name query相对应的是path)
this.$router.push({
name: 'detail', params:{shopid: item.id}});
3、获取参数
this.$route.params.shopid
4、url的表现形式(url中没带参数)
http://localhost:8080/#/mtindex