使用場景如:當在新增/編輯路由頁面提交成功后,需要關閉當前頁,并跳轉回列表頁。
實現代碼:
this.$store.dispatch("tagsView/delView", this.$route); //關閉當前頁
this.$router.replace({ path: "/xxx/xxx" }); // 要打開的頁面
我這里面開啟了若依路由緩存,所以跳回到列表頁時,頁面并不會刷新。如果需要在回到列表頁時主動刷新列表數據,可以在跳轉頁面跳轉前存到本地一個標識,在列表頁actived生命周期
中獲取標識,獲取到后將標識置為初始值(不需刷新的標識),并調用列表刷新方法。
實現代碼:
// 在新增/編輯路由頁面
localStorage.setItem("IndexRefresh", true);
this.$store.dispatch("tagsView/delView", this.$route); //關閉當前頁
this.$router.replace({ path: "/xxx/xxx" }); // 要打開的頁面
// 列表頁
```bash
activated() {if (localStorage.getItem("IndexRefresh") == "true") {localStorage.setItem("IndexRefresh", false);this.getList();}}