Skip to content

Commit 260e6a9

Browse files
author
allen
committed
feat: keep-alive 优化
1 parent 6b02c65 commit 260e6a9

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/components/layout/Header.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import type { RouteLocationRaw, RouteRecordNameGeneric } from 'vue-router'
2+
import type { RouteRecordNameGeneric } from 'vue-router'
33
import { onBeforeRouteUpdate } from 'vue-router'
44
55
const { logout } = useStore('user')

src/pages/index.vue

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
<script lang="ts" setup>
22
const { tabs } = useStore('app')
3+
4+
const router = useRouter()
5+
const routes = router.getRoutes()
6+
const needCacheRouteNames = routes
7+
.filter((item) => item.meta && !item.meta.notCache)
8+
.map((item) => item.name)
9+
10+
const cacheList = computed(() => {
11+
const arr = tabs.value
12+
.map((item) => item.name)
13+
.filter((item) => needCacheRouteNames.includes(item))
14+
return arr
15+
})
316
</script>
417

518
<template>
@@ -14,7 +27,7 @@ const { tabs } = useStore('app')
1427
<el-main>
1528
<router-view v-slot="{ Component, route }">
1629
<transition name="fade-transform" mode="out-in">
17-
<keep-alive :include="tabs.map((i) => i.name)">
30+
<keep-alive :include="cacheList">
1831
<component :is="Component" :key="route.name" />
1932
</keep-alive>
2033
</transition>

0 commit comments

Comments
 (0)