Skip to content

Commit

Permalink
feat: support keep-alive meta config (#470)
Browse files Browse the repository at this point in the history
* feat: support keepalive meta config

* chore: remove console
  • Loading branch information
uyarn authored Apr 13, 2023
1 parent 7642c32 commit 2123e86
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
1 change: 1 addition & 0 deletions mock/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ export default [
component: '/form/step/index',
meta: {
title: '分步表单页',
keepAlive: false,
},
},
],
Expand Down
3 changes: 3 additions & 0 deletions src/api/model/permissionModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,7 @@ export interface RouteMeta {
hidden?: boolean;
hiddenBreadcrumb?: boolean;
single?: boolean;
keepAlive?: boolean;
frameSrc?: string;
frameBlank?: boolean;
}
11 changes: 9 additions & 2 deletions src/layouts/components/Content.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
</template>

<script setup lang="ts">
import isBoolean from 'lodash/isBoolean';
import isUndefined from 'lodash/isUndefined';
import type { ComputedRef } from 'vue';
import { computed } from 'vue';
Expand All @@ -31,8 +33,13 @@ import { useTabsRouterStore } from '@/store';
const aliveViews = computed(() => {
const tabsRouterStore = useTabsRouterStore();
const { tabRouters } = tabsRouterStore;
return tabRouters.filter((route) => route.isAlive).map((route) => route.name);
return tabRouters
.filter((route) => {
const keepAliveConfig = route.meta?.keepAlive;
const isRouteKeepAlive = isUndefined(keepAliveConfig) || (isBoolean(keepAliveConfig) && keepAliveConfig); // 默认开启keepalive
return route.isAlive && isRouteKeepAlive;
})
.map((route) => route.name);
}) as ComputedRef<string[]>;
const isRefreshing = computed(() => {
Expand Down

0 comments on commit 2123e86

Please sign in to comment.