Skip to content

Commit

Permalink
fix: 🧩 keepAlive logic error when modifying and refreshing the page
Browse files Browse the repository at this point in the history
  • Loading branch information
HalseySpicy committed Oct 26, 2023
1 parent 436c1f6 commit 5d8479c
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/components/ProTable/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,9 @@ const setEnumMap = async ({ prop, enum: enumValue }: ColumnProps) => {
// 当前 enum 为静态数据,则直接存储到 enumMap
if (typeof enumValue !== "function") return enumMap.value.set(prop!, unref(enumValue!));

// 为了防止接口执行慢,而存储慢,导致重复请求,所以预先存储为[],接口返回后再二次存储
// 为了防止接口执行慢,而存储慢,导致重复请求,所以预先存储为[]接口返回后再二次存储
enumMap.value.set(prop!, []);

// 当前 enum 为后台数据需要请求数据,则调用该请求接口,并存储到 enumMap
const { data } = await enumValue();
enumMap.value.set(prop!, data);
Expand Down
4 changes: 2 additions & 2 deletions src/layouts/components/Tabs/components/MoreButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,10 @@ const keepAliveStore = useKeepAliveStore();
const refreshCurrentPage: Function = inject("refresh") as Function;
const refresh = () => {
setTimeout(() => {
keepAliveStore.removeKeepAliveName(route.name as string);
route.meta.isKeepAlive && keepAliveStore.removeKeepAliveName(route.name as string);
refreshCurrentPage(false);
nextTick(() => {
keepAliveStore.addKeepAliveName(route.name as string);
route.meta.isKeepAlive && keepAliveStore.addKeepAliveName(route.name as string);
refreshCurrentPage(true);
});
}, 0);
Expand Down
1 change: 1 addition & 0 deletions src/stores/modules/tabs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export const useTabsStore = defineStore({
if (this.tabsMenuList.every(item => item.path !== tabItem.path)) {
this.tabsMenuList.push(tabItem);
}
// add keepalive
if (!keepAliveStore.keepAliveName.includes(tabItem.name) && tabItem.isKeepAlive) {
keepAliveStore.addKeepAliveName(tabItem.name);
}
Expand Down
4 changes: 2 additions & 2 deletions src/views/assembly/tabs/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@ const keepAliveStore = useKeepAliveStore();
const refreshCurrentPage: Function = inject("refresh") as Function;
const refresh = () => {
setTimeout(() => {
keepAliveStore.removeKeepAliveName(route.name as string);
route.meta.isKeepAlive && keepAliveStore.removeKeepAliveName(route.name as string);
refreshCurrentPage(false);
nextTick(() => {
keepAliveStore.addKeepAliveName(route.name as string);
route.meta.isKeepAlive && keepAliveStore.addKeepAliveName(route.name as string);
refreshCurrentPage(true);
});
}, 0);
Expand Down

0 comments on commit 5d8479c

Please sign in to comment.