Skip to content

pagination组件修改 #181

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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