import { getDict } from '@/api/toConsult.js' import dayjs from 'dayjs' 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:{ }, methods: { //根据字典类型获取字典值 getDictHandler(dictType,callBack) { getDict( dictType ).then(res => { let { code, data, msg } = res if (code == 200) { callBack(data) } }) }, //根据字典类型获取字典值,返回字典label getDicts(s,dict){ console.log(this[dict],11111); //判断内存中是否有该字典,没有就去获取 if( !this[dict]){ getDict( dict ).then(res => { let { code, data } = res; if (code == 200) { this[dict] = data; //return this[dict].find(v=> s == v.dictValue).dictLabel; } }) }else { return this[dict].find(v=> s == v.dictValue).dictLabel; } }, } }