import { ref } from "vue"; import { getDataType } from "../../utils/index.js"; /** * @param {Function} api - 接口请求函数,用于获取数据字典内容 * @param {String} id - 数据字典的id * @returns {Array} 返回对象包含以下属性: * - {Ref} 0 - 数据字典数据,使用 Vue 的 ref 包裹的数组,包含字典项列表 */ export default function useDataDictionary(api, id) { if (getDataType(api) !== "Function" && getDataType(api) !== "AsyncFunction") throw new Error("api必须是一个函数"); const data = ref([]); api({ parentId: id }).then((res) => { data.value = res; }); return [data]; }