Skip to content

Commit d34f4db

Browse files
committed
refactor: simplify store imports via central export pattern
1 parent 4f4dcfe commit d34f4db

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

src/App.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script setup lang="ts">
2-
import useRouteCache from '@/stores/modules/routeCache'
2+
import { useRouteCacheStore } from '@/stores'
33
44
useHead({
55
title: 'Vue3 Vant Mobile',
@@ -22,8 +22,10 @@ useHead({
2222
],
2323
})
2424
25+
const routeCacheStore = useRouteCacheStore()
26+
2527
const keepAliveRouteNames = computed(() => {
26-
return useRouteCache().routeCaches as string[]
28+
return routeCacheStore.routeCaches
2729
})
2830
2931
const mode = computed(() => {

src/pages/counter/index.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
import { storeToRefs } from 'pinia'
3-
import useCounterStore from '@/stores/modules/counter'
3+
import { useCounterStore } from '@/stores'
44
55
const counterStore = useCounterStore()
66
const { counter } = storeToRefs(counterStore)

src/router/index.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ import NProgress from 'nprogress'
55
import 'nprogress/nprogress.css'
66

77
import type { EnhancedRouteLocation } from './types'
8-
import useRouteCacheStore from '@/stores/modules/routeCache'
9-
import { useUserStore } from '@/stores'
8+
import { useRouteCacheStore, useUserStore } from '@/stores'
109

1110
import { isLogin } from '@/utils/auth'
1211
import setPageTitle from '@/utils/set-page-title'

src/stores/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import { createPinia } from 'pinia'
22
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
33

44
import useUserStore from './modules/user'
5+
import useCounterStore from './modules/counter'
6+
import useRouteCacheStore from './modules/routeCache'
57

68
const pinia = createPinia()
79
pinia.use(piniaPluginPersistedstate)
810

9-
export { useUserStore }
11+
export { useUserStore, useCounterStore, useRouteCacheStore }
1012
export default pinia

0 commit comments

Comments
 (0)