Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/components/Pagination/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</template>

<script setup lang="ts">
defineProps({
const props = defineProps({
total: {
required: true,
type: Number as PropType<number>,
Expand Down Expand Up @@ -59,7 +59,19 @@ const pageSize = defineModel("limit", {
default: 10,
});

watch(
props.total,
(newVal: number) => {
const lastPage = Math.ceil(newVal / pageSize.value)
if (newVal > 0 && currentPage.value > lastPage) {
currentPage.value = lastPage
emit("pagination", { page: currentPage.value, limit: pageSize.value });
}
}
);

function handleSizeChange(val: number) {
currentPage.value = 1
emit("pagination", { page: currentPage.value, limit: val });
}

Expand Down