App.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <script setup lang="ts">
  2. import { storeToRefs } from 'pinia'
  3. import useAppStore from '@/stores/modules/app'
  4. import useRouteCache from '@/stores/modules/routeCache'
  5. import useRouteTransitionNameStore from '@/stores/modules/routeTransitionName'
  6. import useAutoThemeSwitcher from '@/hooks/useAutoThemeSwitcher'
  7. useHead({
  8. title: 'Vue3 Vant Mobile',
  9. meta: [
  10. {
  11. name: 'description',
  12. content: 'Vue + Vite H5 Starter Template',
  13. },
  14. {
  15. name: 'theme-color',
  16. content: () => isDark.value ? '#00aba9' : '#ffffff',
  17. },
  18. ],
  19. link: [
  20. {
  21. rel: 'icon',
  22. type: 'image/svg+xml',
  23. href: () => preferredDark.value ? '/favicon-dark.svg' : '/favicon.svg',
  24. },
  25. ],
  26. })
  27. const appStore = useAppStore()
  28. const { mode } = storeToRefs(appStore)
  29. const routeTransitionNameStore = useRouteTransitionNameStore()
  30. const { routeTransitionName } = storeToRefs(routeTransitionNameStore)
  31. const { initializeThemeSwitcher } = useAutoThemeSwitcher(appStore)
  32. const keepAliveRouteNames = computed(() => {
  33. return useRouteCache().routeCaches as string[]
  34. })
  35. onMounted(() => {
  36. initializeThemeSwitcher()
  37. })
  38. </script>
  39. <template>
  40. <VanConfigProvider :theme="mode">
  41. <NavBar />
  42. <router-view v-slot="{ Component, route }">
  43. <transition :name="routeTransitionName">
  44. <keep-alive :include="keepAliveRouteNames">
  45. <component :is="Component" :key="route.name" />
  46. </keep-alive>
  47. </transition>
  48. </router-view>
  49. <TabBar />
  50. </VanConfigProvider>
  51. </template>