refactor: 路由多级缓存调整为扁平化方案

This commit is contained in:
2024-05-04 21:45:12 +08:00
parent 308938a0f6
commit 5f3dd93376
5 changed files with 55 additions and 36 deletions

View File

@@ -1,9 +1,9 @@
<template>
<a-layout class="main">
<router-view v-slot="{ Component, route }">
<transition :name="transitionName(route)" mode="out-in" appear>
<transition :name="appStore.transitionName" mode="out-in" appear>
<keep-alive :include="(tabsStore.cacheList as string[])">
<component :is="Component" :key="route.matched?.[1]?.path" />
<component :is="Component" :key="route.path" />
</keep-alive>
</transition>
</router-view>
@@ -11,22 +11,11 @@
</template>
<script setup lang="ts">
import type { RouteLocationNormalizedLoaded } from 'vue-router'
import { useAppStore, useTabsStore } from '@/stores'
defineOptions({ name: 'Main' })
const appStore = useAppStore()
const tabsStore = useTabsStore()
// 过渡动画
const transitionName = computed(() => {
return function (route: RouteLocationNormalizedLoaded) {
if (route?.matched?.[1]?.meta?.animation === false) {
return ''
}
return appStore.transitionName
}
})
</script>
<style lang="scss" scoped>