Skip to content

useList 列表hook

代码示例

ts
const { list, loading, pager, getList } = useList(
    () => axios.get('/api/list'), 
    (data: Record<string, any>[]) => {
        // 处理数据
        // ...
        return data;
    },
);

参数

参数说明类型默认值
requestFun请求函数() => Promise<any>-
callback数据处理函数(data: Record<string, any>[]) => Record<string, any>[]-
useFetch可选项,项目中自己重写的useFetch函数UseFetch-

UseFetch类型定义

ts
type UseFetch = (
    requestFun: () => Promise<AxiosResponse<any>>, 
    callback: (data: any) => void, 
    finallyCallback?: () => void
) => void;

返回值

参数说明类型
list列表数据Ref<Record<string, any>[]>
loading加载状态Ref<boolean>
pager分页信息Ref<{page: number, size: number, total: number}>
getList刷新列表() => void