路由组件传参
1.首页组件获取参数后进行跳转
## result为后端响应数据
onGetData(result){
console.log(result)
this.$router.push({name:"showData",params:{"reponsData":result}});
}
3.路由定义时将数据与$route
解耦
$route
解耦在组件中定义好接受数据的属性
在路由文件中将传递给路由的数据绑定到组件对应的属性中
## 组件文件
export default {
props:['reponsData'],
}
## 路由文件
{path:"/show/",name:"showData",component:showDataPage,props:(route)=>({reponsData:route.params.reponsData})},
参考
Last updated
Was this helpful?