import { reqDictionary } from "@/request/api.js"; import cloneDeep from 'lodash/cloneDeep' const stateReset = { dictionaryInfo: {}, }; const state = cloneDeep(stateReset); const getters = {}; const mutations = { // 重置字典数据 resetVxDictionary(state) { Object.assign(state, cloneDeep(stateReset)) }, // 获取数据 vxDictionary(state, args) { state.dictionaryInfo[args.key] = args.data; }, }; const actions = { // 获取字典数据 async vxDictionary({ commit, state }, args) { if (state.dictionaryInfo[args.key]) { //如果存在 return await Promise.resolve(state.dictionaryInfo[args.key]); } else { let result = await reqDictionary(args); commit("vxDictionary", { key: args.key, data: result }); return result; } }, }; export default { namespaced: true, state, getters, mutations, actions, };