diff --git a/src/usePagination.ts b/src/usePagination.ts index 23814e0..0428020 100644 --- a/src/usePagination.ts +++ b/src/usePagination.ts @@ -99,17 +99,6 @@ function usePagination( run(...mergerParams); }; - const total = computed(() => get(data.value, totalKey, 0)); - const current = computed( - () => (params.value[0] as Record)[currentKey], - ); - const pageSize = computed( - () => (params.value[0] as Record)[pageSizeKey], - ); - const totalPage = computed(() => - get(data.value, totalPageKey, Math.ceil(total.value / pageSize.value)), - ); - // changeCurrent change current page (current: number) => void const changeCurrent = (current: number) => { paging({ [currentKey]: current }); @@ -120,6 +109,23 @@ function usePagination( paging({ [pageSizeKey]: pageSize }); }; + const total = computed(() => get(data.value, totalKey, 0)); + const current = computed({ + get: () => (params.value[0] as Record)[currentKey], + set: (val: number) => { + changeCurrent(val); + }, + }); + const pageSize = computed({ + get: () => (params.value[0] as Record)[pageSizeKey], + set: (val: number) => { + changePageSize(val); + }, + }); + const totalPage = computed(() => + get(data.value, totalPageKey, Math.ceil(total.value / pageSize.value)), + ); + return { data, params,