vue封装字典接口

原创
小哥 2年前 (2022-12-19) 阅读数 43 #大杂烩
  1. 在api定义接口调用

DictionaryData.js

import request from @/utils/request
//查询字典数据列表

//  根据 dictType 查询字典
export function getDictData(params) {
    return request({
        url: /system/dictData/getDictData,
        method: get,
        params
    })
}
  1. 在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] }

    });

    }

  2. 在.vue要使用的文件


    Powered By Z-BlogPHP Theme By 编程老白