import { getDict } from '@/api/toConsult.js' export default { data() { return { //字典['dict_type'] dicts:[] } }, created() { /** 组件中设置dictType,即可获取相应的value*/ if(this.dicts && this.dicts.length > 0){ this.dicts.forEach(item=>{ this.getDictHandler(item,(res)=>{ this[item] = res }) }) } }, computed:{ //根据字典类型获取字典值,返回字典label getDicts(s,dict){ return this[dict].find(v=> s == v.dictValue).dictLabel; }, }, methods: { //根据字典类型获取字典值 getDictHandler(dictType,callBack) { getDict( dictType ).then(res => { let { code, data, msg } = res if (code == 200) { callBack(data) } }) }, } }