vue 路由跳转,参数消失问题

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