mirror of
https://github.com/jekip/naive-ui-admin.git
synced 2026-02-09 16:02:27 +08:00
51 lines
1.4 KiB
Vue
51 lines
1.4 KiB
Vue
<template>
|
|
<RouterView>
|
|
<template #default="{ Component, route }">
|
|
<transition :name="getTransitionName" mode="out-in" appear>
|
|
<keep-alive v-if="keepAliveComponents.length" :include="keepAliveComponents">
|
|
<component :is="Component" :key="route.fullPath" />
|
|
</keep-alive>
|
|
<component v-else :is="Component" :key="route.fullPath" />
|
|
</transition>
|
|
</template>
|
|
</RouterView>
|
|
</template>
|
|
|
|
<script>
|
|
import { defineComponent, computed, unref } from 'vue';
|
|
import { useAsyncRouteStore } from '@/store/modules/asyncRoute';
|
|
import { useProjectSetting } from '@/hooks/setting/useProjectSetting';
|
|
|
|
export default defineComponent({
|
|
name: 'MainView',
|
|
components: {},
|
|
props: {
|
|
notNeedKey: {
|
|
type: Boolean,
|
|
default: false,
|
|
},
|
|
animate: {
|
|
type: Boolean,
|
|
default: true,
|
|
},
|
|
},
|
|
setup() {
|
|
const { isPageAnimate, pageAnimateType } = useProjectSetting();
|
|
const asyncRouteStore = useAsyncRouteStore();
|
|
// 需要缓存的路由组件
|
|
const keepAliveComponents = computed(() => asyncRouteStore.keepAliveComponents);
|
|
|
|
const getTransitionName = computed(() => {
|
|
return unref(isPageAnimate) ? unref(pageAnimateType) : '';
|
|
});
|
|
|
|
return {
|
|
keepAliveComponents,
|
|
getTransitionName,
|
|
};
|
|
},
|
|
});
|
|
</script>
|
|
|
|
<style lang="less" scoped></style>
|