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

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

实现代码:

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();
    }
  }
相关推荐
无限大.1 小时前
前端知识速记--HTML篇:src和href
前端·html
子非鱼9211 小时前
两栏布局、三栏布局、水平垂直居中
前端·javascript·css
程序猿小D2 小时前
第三百五十八节 JavaFX教程 - JavaFX滑块
java·前端·数据库
GISer_Jing3 小时前
React中useState()钩子和函数式组件底层渲染流程详解
前端·react.js·前端框架
私人珍藏库4 小时前
Google Chrome-便携增强版[解压即用]
前端·chrome
我的青春不太冷5 小时前
【实战篇章】深入探讨:服务器如何响应前端请求及后端如何查看前端提交的数据
运维·服务器·前端·学习
Anlici6 小时前
2025前端高频面试题--CSS篇
前端·css
追光少年33226 小时前
Learning Vue 读书笔记 Chapter 4
前端·javascript·vue.js
软件2056 小时前
【Vite + Vue + Ts 项目三个 tsconfig 文件】
前端·javascript·vue.js
老大白菜6 小时前
在 Ubuntu 中使用 FastAPI 创建一个简单的 Web 应用程序
前端·ubuntu·fastapi