优化 keep-alive 缓存方式

This commit is contained in:
吕金泽 2022-08-13 15:00:31 +08:00
parent 49dd4a55eb
commit 1012c419ac
2 changed files with 5 additions and 7 deletions

View File

@ -44,10 +44,9 @@
<div class="main-box">
<el-main>
<router-view v-slot="{ Component }">
<keep-alive>
<component v-if="$route.meta.keepAlive" :is="Component" :key="$route.path" />
<keep-alive :include="$global.visitedViews.filter(it => it.meta.keepAlive).map(it => it.path.substr(it.path.lastIndexOf('/') + 1))">
<component :is="Component" :key="$route.path" />
</keep-alive>
<component v-if="!$route.meta.keepAlive" :is="Component" :key="$route.path" />
</router-view>
</el-main>
</div>

View File

@ -1,8 +1,7 @@
<template>
<router-view v-slot="{ Component }">
<keep-alive>
<component v-if="$route.meta.keepAlive" :is="Component" :key="$route.path" />
<keep-alive :include="$global.visitedViews.filter(it => it.meta.keepAlive).map(it => it.path.substr(it.path.lastIndexOf('/') + 1))">
<component :is="Component" :key="$route.path" />
</keep-alive>
<component v-if="!$route.meta.keepAlive" :is="Component" :key="$route.path" />
</router-view>
</template>
</template>