utils/utils.js
import { reactive, toRefs } from 'vue'
import { useStore } from 'vuex'
export default function () {
const store = useStore()
const dictionary = reactive({
dictionaryMap: {},
dictionaryList: []
})
const getDictionary = async (code) => {
const response = await store.dispatch('dictionary/getDictionary', code)
dictionary.dictionaryList = response
const result = {}
response.forEach(item => {
result[item.value] = item.label
})
dictionary.dictionaryMap = result
return { list: response, map: result }
}
return {
...toRefs(dictionary),
getDictionary
}
}
引入
import useDictionary from '@/mixins/dictionary'
const { dictionaryMap, dictionaryList, getDictionary } = useDictionary()
使用
onBeforeMount(() => {
getDictionary('login')
getCaptcha()
notifyHandle()
})