indexAsync.vue 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <!-- 💥 这里是异步加载 LayoutComponents -->
  2. <template>
  3. <suspense>
  4. <template #default>
  5. <component :is="LayoutComponents[layout]" />
  6. </template>
  7. <template #fallback>
  8. <Loading />
  9. </template>
  10. </suspense>
  11. <ThemeDrawer />
  12. </template>
  13. <script setup lang="ts" name="layoutAsync">
  14. import { computed, defineAsyncComponent, type Component } from "vue";
  15. import { LayoutType } from "@/stores/interface";
  16. import { useGlobalStore } from "@/stores/modules/global";
  17. import Loading from "@/components/Loading/index.vue";
  18. import ThemeDrawer from "./components/ThemeDrawer/index.vue";
  19. const LayoutComponents: Record<LayoutType, Component> = {
  20. vertical: defineAsyncComponent(() => import("./LayoutVertical/index.vue")),
  21. classic: defineAsyncComponent(() => import("./LayoutClassic/index.vue")),
  22. transverse: defineAsyncComponent(() => import("./LayoutTransverse/index.vue")),
  23. columns: defineAsyncComponent(() => import("./LayoutColumns/index.vue"))
  24. };
  25. const globalStore = useGlobalStore();
  26. const layout = computed(() => globalStore.layout);
  27. </script>
  28. <style scoped lang="scss">
  29. .layout {
  30. min-width: 730px;
  31. }
  32. </style>