diff --git a/src/utils/dict.ts b/src/utils/dict.ts index 6519ce62dcc0578cf2e8c56e64e52266d71232b8..b3f3905d4b4be5584f82e11a71737e901101dc03 100644 --- a/src/utils/dict.ts +++ b/src/utils/dict.ts @@ -3,7 +3,14 @@ */ import { useDictStore } from '@/store' -const dictStore = useDictStore() +let cachedDictStore = null + +const getDictStore = () => { + if (!cachedDictStore) { + cachedDictStore = useDictStore() + } + return cachedDictStore +} /** * 获取 dictType 对应的数据字典数组 * @@ -27,6 +34,7 @@ export interface StringDictDataType extends DictDataType { } export const getDictOptions = (dictType: string) => { + const dictStore = getDictStore() // 确保仅在第一次调用时初始化 return dictStore.getDictByType(dictType) || [] }