vue-router在4.14版本就废弃这种传参方式了
原因:这种传参本来就不是官方推荐的,比如页面刷新会引起参数丢失
官方解释
官方解释翻译后的截图:
解决(官方推荐了很多种解决方式,下面列举出快捷高效的修改方式):
1、参数简单的话就这样改
javascript">const routes = [{path: '/detail/:id',name: 'Detail',component: Detail}
];
// 出发
this.$router.push({ name: 'Detail', params: { id: 123 } });
// 目标页面获取
this.$route.params.idconst routes = [{path: '/yourpath/:param1/:param2',name: 'YourComponent',component: YourComponent}
];
// 出发
this.$router.push({ name: 'YourComponent', params: { param1: 'value1', param2: 'value2' } });
// 目标页面获取
this.$route.params.value1
this.$route.params.value2
2、参数复杂–query方式传参
记得this.$router.push的时候序列化一下,否则你拿到的可能是 “[object Object]”
javascript">this.$router.push({ name: 'Detail', query: { device: JSON.stringify(device)} });
//获取参数:
JSON.parse(this.$route.query.device)