From 1fb40a31e4272d3d5134924eda221e0d96f67a81 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Fri, 1 Oct 2021 17:08:51 +0800 Subject: [PATCH] fix: table pagination current error --- components/table/hooks/usePagination.ts | 30 +++++++++++++------------ 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/components/table/hooks/usePagination.ts b/components/table/hooks/usePagination.ts index a0710b148..dd6d03ca5 100644 --- a/components/table/hooks/usePagination.ts +++ b/components/table/hooks/usePagination.ts @@ -63,20 +63,22 @@ export default function usePagination( })); // ============ Basic Pagination Config ============ - const mergedPagination = computed(() => - extendsObject>(innerPagination.value, pagination.value, { - total: paginationTotal.value > 0 ? paginationTotal.value : totalRef.value, - }), - ); - - // Reset `current` if data length or pageSize changed - const maxPage = Math.ceil( - (paginationTotal.value || totalRef.value) / mergedPagination.value.pageSize!, - ); - if (mergedPagination.value.current! > maxPage) { - // Prevent a maximum page count of 0 - mergedPagination.value.current = maxPage || 1; - } + const mergedPagination = computed(() => { + const mP = extendsObject>( + innerPagination.value, + pagination.value, + { + total: paginationTotal.value > 0 ? paginationTotal.value : totalRef.value, + }, + ); + // Reset `current` if data length or pageSize changed + const maxPage = Math.ceil((paginationTotal.value || totalRef.value) / mP.pageSize!); + if (mP.current! > maxPage) { + // Prevent a maximum page count of 0 + mP.current = maxPage || 1; + } + return mP; + }); const refreshPagination = (current = 1, pageSize?: number) => { if (pagination.value === false) return;