vue 路由参数的传递和获取

路由传参的方式

// 类似于get请求,地址栏显示参数
1.this.$router.push({path:'/about',query:{id:1}});
// 类似于get请求,地址栏显示参数
2.this.$router.push({name:'about',query:{id:1}); 
// 推荐使用,类似于post请求,地址栏不显示参数,没有参数大小限制
3.this.$router.push({name:'about',params:{id:1}}); 

注意:

查询方式 query参数 params参数
使用path时 值能正常获取,在地址栏展示参数,类似于get 不能正常获取,值为空
使用name时 值能正常获取,在地址栏展示参数,类似于get 值能正常获取,地址栏不展示参数,类似于post

路由获取参数

1.this.$route.query
2.this.$route.params

评论

暂无评论