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> <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>

View File

@ -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()
}, },

View File

@ -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
},
}, },
}) })