fix: keep-alive key
This commit is contained in:
parent
85a04fd06d
commit
8806a6cb43
@ -1,7 +1,7 @@
|
|||||||
<template>
|
<template>
|
||||||
<router-view v-slot="{ Component, route }">
|
<router-view v-slot="{ Component, route }">
|
||||||
<KeepAlive :include="keepAliveRouteNames">
|
<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>
|
</KeepAlive>
|
||||||
</router-view>
|
</router-view>
|
||||||
</template>
|
</template>
|
||||||
|
@ -13,6 +13,7 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { useTagsStore, useAppStore } from '@/store'
|
import { useTagsStore, useAppStore } from '@/store'
|
||||||
import { renderIcon } from '@/utils'
|
import { renderIcon } from '@/utils'
|
||||||
|
import { useLocalStorage } from '@vueuse/core'
|
||||||
|
|
||||||
const props = defineProps({
|
const props = defineProps({
|
||||||
show: {
|
show: {
|
||||||
@ -78,7 +79,7 @@ const actionMap = new Map([
|
|||||||
() => {
|
() => {
|
||||||
if (route.meta?.keepAlive) {
|
if (route.meta?.keepAlive) {
|
||||||
// 重置keepAlive
|
// 重置keepAlive
|
||||||
route.meta.key = +new Date()
|
appStore.setAliveKeys(route.name, +new Date())
|
||||||
}
|
}
|
||||||
appStore.reloadPage()
|
appStore.reloadPage()
|
||||||
},
|
},
|
||||||
|
@ -5,6 +5,8 @@ export const useAppStore = defineStore('app', {
|
|||||||
return {
|
return {
|
||||||
reloadFlag: true,
|
reloadFlag: true,
|
||||||
collapsed: false,
|
collapsed: false,
|
||||||
|
/** keepAlive路由的key,重新赋值可重置keepAlive */
|
||||||
|
aliveKeys: {},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
@ -25,5 +27,8 @@ export const useAppStore = defineStore('app', {
|
|||||||
setCollapsed(collapsed) {
|
setCollapsed(collapsed) {
|
||||||
this.collapsed = collapsed
|
this.collapsed = collapsed
|
||||||
},
|
},
|
||||||
|
setAliveKeys(key, val) {
|
||||||
|
this.aliveKeys[key] = val
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user