vue 路由跳转,参数消失问题
1. 参数传递页面:这种方式页面刷新参数丢失。
// 点击跳转详情页面
toDetail(){
this.$router.push({
name:"newsDetail",
params:{content:item}//传递过去的参数
})
}
页面取参数 :this.$route.params.comtent
2. 刷新参数不会丢失
this.$router.push({
path: "/newsDetail",
query: {
content: JSON.stringify(item),
},
});
页面取参数 :this.$route.query.comtent // 此处使用时应用JSON.parse转换参数
3. 参数不会丢失
路由配置
{
path: "workDetail/:id",
name: "WorkDetail",
component: () => import("@/page/workDetail")
}
页面跳转事件
getDetail(id) {
this.$router.push("/workDetail/" + id);
},
取参: this.$route.params.id
本文章为转载内容,我们尊重原作者对文章享有的著作权。如有内容错误或侵权问题,欢迎原作者联系我们进行内容更正或删除文章。