fix:修复keep-alive失效问题,并添加keep-alive测试页面

This commit is contained in:
zhangchuanlong
2022-03-04 16:44:33 +08:00
parent 402c7db7ba
commit 8bcbcac531
5 changed files with 51 additions and 18 deletions

View File

@@ -1,9 +1,19 @@
<template>
<router-view>
<template #default="{ Component, route }">
<transition name="fade-slide" mode="out-in" appear>
<component :is="Component" :key="route.fullPath"></component>
</transition>
</template>
<router-view v-slot="{ Component, route }">
<transition name="fade-slide" mode="out-in" appear>
<keep-alive :include="keepAliveRouteNames">
<component :is="Component" :key="route.path" />
</keep-alive>
</transition>
</router-view>
</template>
<script setup>
import { computed } from 'vue'
import { useRouter } from 'vue-router'
const router = useRouter()
const allRoutes = router.getRoutes()
const keepAliveRouteNames = computed(() => {
return allRoutes.filter((route) => route.meta?.keepAlive).map((route) => route.name)
})
</script>