vue 路由 实现点击传参并实现路由跳转
component:A
<div @click=' transferParameters()'></div>
script:
export default {
methods:{
transferParameters() {
this.$router.push({
path:"/组件B的路径",
query:{//通过query 传递参数
goodsDetail:需要传递的参数,
}
});
},
}
}
component:B
<div></div>
export default {
mounted(){
this.getGoodsDetail ();
},
methods: {
getGoodsDetail() {
let routerParams = this.$route.query.goodsDetail;
}
}
}
desc:
传递参数:$router
接收参数:$route
返回上一页:
this.$router.go(-1)