pagination

This commit is contained in:
2026-04-03 19:58:56 +05:30
parent 9b87fb31a7
commit f8cea025a3
6 changed files with 62 additions and 9 deletions

View File

@@ -13,7 +13,11 @@ export function useResource<T = any>(config: ResourceConfig) {
queryFn: async () => {
// @ts-ignore
const res = await api.get<T[]>(endpoint, { params });
return res.data;
const total = res.headers ? parseInt(res.headers['x-total-count'] || res.headers['X-Total-Count']) : undefined;
return {
data: res.data,
total: isNaN(total as any) ? undefined : total
};
}
});
@@ -77,7 +81,11 @@ export function useResource<T = any>(config: ResourceConfig) {
queryFn: async () => {
// @ts-ignore
const res = await api.get<T[]>(endpoint, { params });
return res.data;
const total = res.headers ? parseInt(res.headers['x-total-count'] || res.headers['X-Total-Count']) : undefined;
return {
data: res.data,
total: isNaN(total as any) ? undefined : total
};
},
});