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

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

实现代码:

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();
    }
  }
相关推荐
ricardo19734 小时前
代码分割 + 路由懒加载 + 字体子集化:前端瘦身三板斧
前端·面试
dsyyyyy11014 小时前
CSS 2D 效果、3D 效果 与 Animation 总结
前端·css·3d
jerrywus4 小时前
Vibe Coding 实战:三天,一个人,一个 Claude Session Viewer——给三家 AI CLI 当统一会话浏览器
前端·claude·gemini
GISer_Jing4 小时前
Three.js渲染架构:从WebGL到WebGPU的演进
javascript·架构·webgl
lichenyang4534 小时前
HarmonyOS AI 聊天模块架构复盘:从 UI、状态、Controller 到 Provider、SSE 与业务卡片
前端
px不是xp4 小时前
【灶台导航】个人中心模块开发实战
javascript·微信·腾讯云·notepad++
wanger615 小时前
AI Agent
前端·javascript·人工智能
徐小夕5 小时前
面试官:AI生成到90%突然断了,你的解决方案是什么?(万字长文深度剖析)
前端·vue.js·算法
剑神一笑5 小时前
Linux zip 与 unzip 命令详解:压缩算法原理与实战技巧
linux·前端·chrome