【若依】关闭当前标签页并跳转路由到其他页面

使用场景如:当在新增/编辑路由页面提交成功后,需要关闭当前页,并跳转回列表页。

实现代码:

bash 复制代码
this.$store.dispatch("tagsView/delView", this.$route); //关闭当前页
this.$router.replace({ path: "/xxx/xxx" }); // 要打开的页面

我这里面开启了若依路由缓存,所以跳回到列表页时,页面并不会刷新。如果需要在回到列表页时主动刷新列表数据,可以在跳转页面跳转前存到本地一个标识,在列表页actived生命周期中获取标识,获取到后将标识置为初始值(不需刷新的标识),并调用列表刷新方法。

实现代码:

bash 复制代码
// 在新增/编辑路由页面
localStorage.setItem("IndexRefresh", true);
this.$store.dispatch("tagsView/delView", this.$route); //关闭当前页
this.$router.replace({ path: "/xxx/xxx" }); // 要打开的页面
bash 复制代码
// 列表页
```bash
activated() {
    if (localStorage.getItem("IndexRefresh") == "true") {
      localStorage.setItem("IndexRefresh", false);
      this.getList();
    }
  }
相关推荐
NiceCloud喜云2 小时前
Opus 4.8 的 Effort Control 怎么选:Low 到 Max 五档策略
android·java·大数据·前端·c++·python·spring
wordbaby2 小时前
React Native + RNOH:跨页面数据回传的最佳实践与避坑指南
前端·react native
GISer_Jing2 小时前
Three.js着色器编译机制深度解析
javascript·webgl·着色器
丷丩2 小时前
MapLibre GL JS第22课:查看本地GeoJSON
前端·javascript·map·mapbox·maplibre gl js
油炸自行车2 小时前
Claude Code 错误:API Error: 400 Failed to deserialize the JSON body into the
开发语言·javascript·json·trae·claude code·api error 400
Front思3 小时前
AI前端工程师需要具备能力+
前端·人工智能·ai
ZC跨境爬虫5 小时前
跟着 MDN 学CSS day_29:(掌握文本与字体样式的核心艺术)
前端·css·ui·html·tensorflow
李子琪。6 小时前
网络空间安全深度实战:CSRF 漏洞原理剖析与基于 Token 的纵深防御体系构建(全栈实验报告)
前端·安全·csrf
冰暮流星6 小时前
javascript之history对象介绍
前端·笔记
IT_陈寒6 小时前
Vite热更新失灵?你可能漏了这个配置
前端·人工智能·后端