fix: keep-alive key
This commit is contained in:
parent
85a04fd06d
commit
8806a6cb43
@ -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>
|
||||
|
@ -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()
|
||||
},
|
||||
|
@ -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
|
||||
},
|
||||
},
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user