ParentView.vue 1.8 KB
Newer Older
V
vben 已提交
1 2 3 4 5
<!--
 * @Description: The reason is that tsx will report warnings under multi-level nesting.
-->
<template>
  <div>
V
vben 已提交
6
    <RouterView>
V
vben 已提交
7
      <template #default="{ Component, route }">
V
vben 已提交
8 9 10 11 12 13 14 15 16 17 18 19 20 21
        <transition
          :name="
            getTransitionName({
              route,
              openCache: openCache,
              enableTransition: getEnableTransition,
              cacheTabs: getCaches,
              def: getBasicTransition,
            })
          "
          mode="out-in"
          appear
        >
          <keep-alive v-if="openCache" :include="getCaches">
22
            <component :is="Component" v-bind="getKey(Component, route)" />
V
vben 已提交
23
          </keep-alive>
24
          <component v-else :is="Component" v-bind="getKey(Component, route)" />
V
vben 已提交
25
        </transition>
V
vben 已提交
26
      </template>
V
vben 已提交
27
    </RouterView>
V
vben 已提交
28 29 30 31 32 33 34 35 36
  </div>
</template>
<script lang="ts">
  import { computed, defineComponent, unref } from 'vue';

  import { useRootSetting } from '/@/hooks/setting/useRootSetting';
  import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting';

  import { useTransitionSetting } from '/@/hooks/setting/useTransitionSetting';
37
  import { useCache, getKey } from './useCache';
V
vben 已提交
38
  import { getTransitionName } from './transition';
V
vben 已提交
39 40

  export default defineComponent({
41
    parentView: true,
V
vben 已提交
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57
    setup() {
      const { getCaches } = useCache(false);

      const { getShowMultipleTab } = useMultipleTabSetting();

      const { getOpenKeepAlive } = useRootSetting();

      const { getBasicTransition, getEnableTransition } = useTransitionSetting();

      const openCache = computed(() => unref(getOpenKeepAlive) && unref(getShowMultipleTab));

      return {
        getCaches,
        getBasicTransition,
        openCache,
        getEnableTransition,
V
vben 已提交
58
        getTransitionName,
59
        getKey,
V
vben 已提交
60 61 62 63
      };
    },
  });
</script>