Skip to content

Commit ea5a238

Browse files
committed
refactor(usePagination): current and pageSize can modify and can trigger request
1 parent 580acfc commit ea5a238

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/usePagination.ts

+17-11
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,6 @@ function usePagination<R, P extends unknown[], FR>(
9999
run(...mergerParams);
100100
};
101101

102-
const total = computed<number>(() => get(data.value, totalKey, 0));
103-
const current = computed(
104-
() => (params.value[0] as Record<string, number>)[currentKey],
105-
);
106-
const pageSize = computed(
107-
() => (params.value[0] as Record<string, number>)[pageSizeKey],
108-
);
109-
const totalPage = computed<number>(() =>
110-
get(data.value, totalPageKey, Math.ceil(total.value / pageSize.value)),
111-
);
112-
113102
// changeCurrent change current page (current: number) => void
114103
const changeCurrent = (current: number) => {
115104
paging({ [currentKey]: current });
@@ -120,6 +109,23 @@ function usePagination<R, P extends unknown[], FR>(
120109
paging({ [pageSizeKey]: pageSize });
121110
};
122111

112+
const total = computed<number>(() => get(data.value, totalKey, 0));
113+
const current = computed({
114+
get: () => (params.value[0] as Record<string, number>)[currentKey],
115+
set: (val: number) => {
116+
changeCurrent(val);
117+
},
118+
});
119+
const pageSize = computed({
120+
get: () => (params.value[0] as Record<string, number>)[pageSizeKey],
121+
set: (val: number) => {
122+
changePageSize(val);
123+
},
124+
});
125+
const totalPage = computed<number>(() =>
126+
get(data.value, totalPageKey, Math.ceil(total.value / pageSize.value)),
127+
);
128+
123129
return {
124130
data,
125131
params,

0 commit comments

Comments
 (0)