export function useDictOptions<T = any>(options: Options) { const optionsData: any = reactive({}) const optionsKey = Object.keys(options) const apiLists = optionsKey.map((key) => { const value = options[key] optionsData[key] = [] return () => value.api(toRaw(value.params) || {}) }) const refresh = async () => { const res = await Promise.allSettled<Promise<any>>(apiLists.map((api) => api())) res.forEach((item, index) => { const key = optionsKey[index] if (item.status == 'fulfilled') { const { transformData } = options[key] const data = transformData ? transformData(item.value) : item.value optionsData[key] = data } }) } refresh() return { optionsData: optionsData as T, refresh } }

export function useDictOptions<T = any>(options: Options) { const optionsData: any = reactive({}) const optionsKey = Object.keys(options) const apiLists = optionsKey.map((key) => { const value = options[key] optionsData[key] = [] return () => value.api(toRaw(value.params) || {}) }) const refresh = async () => { const res = await Promise.allSettled<Promise<any>>(apiLists.map((api) => api())) res.forEach((item, index) => { const key = optionsKey[index] if (item.status == 'fulfilled') { const { transformData } = options[key] const data = transformData ? transformData(item.value) : item.value optionsData[key] = data } }) } refresh() return { optionsData: optionsData as T, refresh } }
用户493773632
08月20日 12:25
|
浏览 28
前端

[]

我要提问
复制内容
分享给好友
AI编程问答网 免责声明:
以上内容除特别注明外均来源于网友提问,AI编程问答网回答,权益归原著者所有;