学无先后,达者为师

网站首页 Vue 正文

vue路由跳转参数丢失

作者:L、yan 更新时间: 2022-03-04 Vue
// 传参
toDetail(){
        this.$router.push({
            name:"newsDetail",
            params:{content:item}//传递过去的参数
        })
    }


// 取参
this.$route.params.comtent

这种参数会丢失

// 传参
this.$router.push({
      path: "/newsDetail",
      query: {
        content: JSON.stringify(item),
      },
    });


// 取参
this.$route.query.comtent // json记得转换

这种不会丢失

// 路由配置
{
      path: "workDetail/:id",
      name: "WorkDetail",
      component: () => import("@/page/workDetail")
 }


// 跳转事件
getDetail(id) {
      this.$router.push("/workDetail/" + id);
    },

也不会丢失

原文链接:https://blog.csdn.net/weixin_45966782/article/details/122343848

栏目分类
最近更新