vue封装字典接口
原创-
在api定义接口调用
DictionaryData.js
import request from @/utils/request
//查询字典数据列表
// 根据 dictType 查询字典
export function getDictData(params) {
return request({
url: /system/dictData/getDictData,
method: get,
params
})
}
-
在utils/index.js文件,定义全局方法
import { getDictData} from "@/api/DictionaryData" export function dictionaries(that, key, code) { let params = { dictType: code } getDictData(params).then(res => { if (res.data) { // that[key] = [{ name: "全部", value: "" }] that[key] = [...that[key], ...res.data] }
});
}
-
在.vue要使用的文件
Powered By Z-BlogPHP Theme By 编程老白