ParentView.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <!--
  2. * @Description: The reason is that tsx will report warnings under multi-level nesting.
  3. -->
  4. <template>
  5. <div>
  6. <router-view>
  7. <template v-slot="{ Component, route }">
  8. <transition
  9. :name="
  10. getTransitionName({
  11. route,
  12. openCache: openCache,
  13. enableTransition: getEnableTransition,
  14. cacheTabs: getCaches,
  15. def: getBasicTransition,
  16. })
  17. "
  18. mode="out-in"
  19. appear
  20. >
  21. <keep-alive v-if="openCache" :include="getCaches">
  22. <component :is="Component" v-bind="getKey(Component, route)" />
  23. </keep-alive>
  24. <component v-else :is="Component" v-bind="getKey(Component, route)" />
  25. </transition>
  26. </template>
  27. </router-view>
  28. </div>
  29. </template>
  30. <script lang="ts">
  31. import { computed, defineComponent, unref } from 'vue';
  32. import { useRootSetting } from '/@/hooks/setting/useRootSetting';
  33. import { useMultipleTabSetting } from '/@/hooks/setting/useMultipleTabSetting';
  34. import { useTransitionSetting } from '/@/hooks/setting/useTransitionSetting';
  35. import { useCache, getKey } from './useCache';
  36. import { getTransitionName } from './transition';
  37. export default defineComponent({
  38. parentView: true,
  39. setup() {
  40. const { getCaches } = useCache(false);
  41. const { getShowMultipleTab } = useMultipleTabSetting();
  42. const { getOpenKeepAlive } = useRootSetting();
  43. const { getBasicTransition, getEnableTransition } = useTransitionSetting();
  44. const openCache = computed(() => unref(getOpenKeepAlive) && unref(getShowMultipleTab));
  45. return {
  46. getCaches,
  47. getBasicTransition,
  48. openCache,
  49. getEnableTransition,
  50. getTransitionName,
  51. getKey,
  52. };
  53. },
  54. });
  55. </script>