Skip to content

Commit

Permalink
refactor(usePagination): current and pageSize can modify and can …
Browse files Browse the repository at this point in the history
…trigger request
  • Loading branch information
John60676 committed Feb 25, 2021
1 parent 580acfc commit ea5a238
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/usePagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,17 +99,6 @@ function usePagination<R, P extends unknown[], FR>(
run(...mergerParams);
};

const total = computed<number>(() => get(data.value, totalKey, 0));
const current = computed(
() => (params.value[0] as Record<string, number>)[currentKey],
);
const pageSize = computed(
() => (params.value[0] as Record<string, number>)[pageSizeKey],
);
const totalPage = computed<number>(() =>
get(data.value, totalPageKey, Math.ceil(total.value / pageSize.value)),
);

// changeCurrent change current page (current: number) => void
const changeCurrent = (current: number) => {
paging({ [currentKey]: current });
Expand All @@ -120,6 +109,23 @@ function usePagination<R, P extends unknown[], FR>(
paging({ [pageSizeKey]: pageSize });
};

const total = computed<number>(() => get(data.value, totalKey, 0));
const current = computed({
get: () => (params.value[0] as Record<string, number>)[currentKey],
set: (val: number) => {
changeCurrent(val);
},
});
const pageSize = computed({
get: () => (params.value[0] as Record<string, number>)[pageSizeKey],
set: (val: number) => {
changePageSize(val);
},
});
const totalPage = computed<number>(() =>
get(data.value, totalPageKey, Math.ceil(total.value / pageSize.value)),
);

return {
data,
params,
Expand Down

0 comments on commit ea5a238

Please sign in to comment.