Vue3 使用element-plus 点击table跳转其他页面带参数并进行查询,(解决路由传参刷新页面参数没有清空)

封装方法 utils.js

//只执行一次type就传递once
export function routeParams(queryParams, type = 'once') {
  const params = JSON.parse(localStorage.getItem('jumpParams'))
  if (params) {
    for (const key in params) {
      if (Object.hasOwnProperty.call(params, key)) {
        const element = params[key];
        queryParams[key] = element
      }
    }
  }
  if (type === 'once') {
    localStorage.removeItem('jumpParams')
  }
}

使用方法

全局注册

import { onceRouteParams } from "@/utils/T_utils";
app.config.globalProperties.onceRouteParams = onceRouteParams; //传递参数只执行一次

1.需要跳转的页面

 const params = {
    key: value
  }
  localStorage.setItem('jumpParams', JSON.stringify(params))
  router.push({ path: '路由'})

2.需要接收的页面

 proxy.onceRouteParams(queryParams.value)
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容