fix(pagination): 🐛 修复watch监听props.total导致的TypeScript类型错误
closed #IBJY7R
This commit is contained in:
@@ -53,6 +53,7 @@ const currentPage = defineModel("page", {
|
|||||||
required: true,
|
required: true,
|
||||||
default: 1,
|
default: 1,
|
||||||
});
|
});
|
||||||
|
|
||||||
const pageSize = defineModel("limit", {
|
const pageSize = defineModel("limit", {
|
||||||
type: Number,
|
type: Number,
|
||||||
required: true,
|
required: true,
|
||||||
@@ -60,18 +61,18 @@ const pageSize = defineModel("limit", {
|
|||||||
});
|
});
|
||||||
|
|
||||||
watch(
|
watch(
|
||||||
props.total,
|
() => props.total,
|
||||||
(newVal: number) => {
|
(newVal: number) => {
|
||||||
const lastPage = Math.ceil(newVal / pageSize.value)
|
const lastPage = Math.ceil(newVal / pageSize.value);
|
||||||
if (newVal > 0 && currentPage.value > lastPage) {
|
if (newVal > 0 && currentPage.value > lastPage) {
|
||||||
currentPage.value = lastPage
|
currentPage.value = lastPage;
|
||||||
emit("pagination", { page: currentPage.value, limit: pageSize.value });
|
emit("pagination", { page: currentPage.value, limit: pageSize.value });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
function handleSizeChange(val: number) {
|
function handleSizeChange(val: number) {
|
||||||
currentPage.value = 1
|
currentPage.value = 1;
|
||||||
emit("pagination", { page: currentPage.value, limit: val });
|
emit("pagination", { page: currentPage.value, limit: val });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user