Intro

分页逻辑

Api

index.d.ts
import type { UseAsyncStateOptions } from '../use-async-state';
export * from './types';
import type { PagingParamsDTO, PagingResultDTO, PagingService } from './types';
export declare type UsePagingOption<R> = UseAsyncStateOptions<PagingResultDTO<R>, [PagingParamsDTO]> & {
    defaultPageSize?: number;
};
export declare function usePaging<RowType>(pagingService: PagingService<RowType>, { defaultPageSize, ...others }?: UsePagingOption<RowType>): {
    list: import("vue").ComputedRef<RowType[] | undefined>;
    paginationState: {
        total: number;
        currentPage: number;
        pageSize: number;
        'onUpdate:currentPage': (pageNumber: number) => Promise<void>;
        'onUpdate:pageSize': (pageSize: number) => Promise<void>;
    };
    goPage: (n: number) => Promise<void>;
    rawData: import("vue").Ref<PagingResultDTO<RowType> | undefined>;
    loading: Readonly<import("vue").Ref<boolean>>;
    error: Readonly<import("vue").Ref<Readonly<unknown>>>;
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
types.d.ts
export interface PagingParamsDTO {
    pageNumber: number;
    pageSize: number;
    offset: number;
    count: number;
    [k: string]: any;
}
export declare type PagingResultDTO<R> = {
    total: number;
    list: R[];
    [k: string]: any;
};
export interface PagingService<R> {
    (p: Record<string, any>): Promise<PagingResultDTO<R>>;
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15