fix: keep-alive key

This commit is contained in:
张传龙 2022-09-24 14:44:59 +08:00
parent 85a04fd06d
commit 8806a6cb43
3 changed files with 8 additions and 2 deletions

View File

@ -1,7 +1,7 @@
<template>
<router-view v-slot="{ Component, route }">
<KeepAlive :include="keepAliveRouteNames">
<component :is="Component" v-if="appStore.reloadFlag" :key="route.meta?.key || route.fullPath" />
<component :is="Component" v-if="appStore.reloadFlag" :key="appStore.aliveKeys[route.name] || route.fullPath" />
</KeepAlive>
</router-view>
</template>

View File

@ -13,6 +13,7 @@
<script setup>
import { useTagsStore, useAppStore } from '@/store'
import { renderIcon } from '@/utils'
import { useLocalStorage } from '@vueuse/core'
const props = defineProps({
show: {
@ -78,7 +79,7 @@ const actionMap = new Map([
() => {
if (route.meta?.keepAlive) {
// keepAlive
route.meta.key = +new Date()
appStore.setAliveKeys(route.name, +new Date())
}
appStore.reloadPage()
},

View File

@ -5,6 +5,8 @@ export const useAppStore = defineStore('app', {
return {
reloadFlag: true,
collapsed: false,
/** keepAlive路由的key重新赋值可重置keepAlive */
aliveKeys: {},
}
},
actions: {
@ -25,5 +27,8 @@ export const useAppStore = defineStore('app', {
setCollapsed(collapsed) {
this.collapsed = collapsed
},
setAliveKeys(key, val) {
this.aliveKeys[key] = val
},
},
})