vue全局字典值获取方法一例
//全局加载字典值 下面采用config.dicts[‘sys_yes_no’] 或config.dicts.sys_yes_no
config为public目录下全局配置对象
import * as apiDict from "@/api/system/dict"//全局加载字典值 下面采用config.dicts['sys_yes_no'] 或config.dicts.sys_yes_no
var dict_sys_yes_no=apiDict.getDict('sys_yes_no');//js中字典用法
export default {name: "aishape",components: {},dicts:["sys_yes_no"],data() {return {//avue-form选项formOption: {detail: false,labelWidth: 120,submitText: '保存',//mockBtn:false,//printBtn:false,submitBtn: true,emptyBtn: false,group: [{label: "是否默认添加",prop: "defaultadd",maxlength: 0,clearable: false,disabled: false,span: 12,type: 'select',dicData: config.dicts['sys_yes_no'],rules: [{required: false, message: '不能为空', trigger: 'blur',}],},]}},
// 根据字典类型查询字典数据信息
export function getDicts(dictType) {return request({url: '/system/dict/data/type', method: 'get', params: {dictType: dictType}})
}
//同步 获取字典值
export async function getDict(type)
{await this.getDicts(type).then(r=>{let t=[];for(var i=0;i<r.data.length;i++){let row=r.data[i];t.push({label:row.dictLabel,value:row.dictValue});}if(!config.dicts[type]){config.dicts[type]=t;}debugger;return t;});
};