<BasePagination /> · A set of pagination options.
<template>
<BasePagination
v-model:page="page"
:items-per-page="8"
:total="512"
:sibling-count="2"
/>
</template>
<script setup lang="ts">
const route = useRoute()
const router = useRouter()
const page = computed({
get() {
return Number(route.query.page) || 1
},
set(value: number) {
router.replace({ query: { ...route.query, page: value } })
},
})
</script>
You can use this component as a self closing one or with its slots to customize the pagination buttons layout.
<template>
<BasePagination>
<div>
<BasePaginationButtonFirst />
<BasePaginationButtonPrev />
</div>
<BasePaginationItems />
<div>
<BasePaginationButtonNext />
<BasePaginationButtonLast />
</div>
</BasePagination>
</template>
This component has props that you can use to modify its visual style.
| Prop | Type |
|---|---|
items-per-pagedefault: - | numberNumber of items per page |
variantdefault: "primary" | "primary" | "dark"The color of the pagination active button. |
sizedefault: "md" | "md" | "sm" | "lg"The size of the pagination buttons. |
roundeddefault: "sm" | "none" | "md" | "sm" | "lg" | "full"The radius of the pagination. |
pagedefault: - | numberThe controlled value of the current page. Can be binded as `v-model:page`. |
default-pagedefault: - | numberThe value of the page that should be active when initially rendered. Use when you do not need to control the value state. |
totaldefault: - | numberNumber of items in your list |
sibling-countdefault: - | numberNumber of sibling should be shown around the current page |
disableddefault: - | booleanWhen `true`, prevents the user from interacting with item |
show-edgesdefault: true | booleanWhen `true`, always show first page, last page, and ellipsis |
as-childdefault: - | booleanChange the default rendered element for the one passed as a child, merging their props and behavior. Read our [Composition](https://www.reka-ui.com/docs/guides/composition) guide for more details. |
asdefault: - | AsTag | ComponentThe element or component this component should render as. Can be overwritten by `asChild`. |
| Event | Emitted Value Type |
|---|---|
update:page | [value: number] |
| Slot | Type |
|---|---|
#default | { items: ({ type: "ellipsis"; } | { type: "page"; value: number; })[]; } |
#ellipsis | any |
#page | { page: number; } |
Use the variant prop to change the color of the pagination.
<template>
<BasePagination
v-model:page="page"
:items-per-page="8"
:total="512"
:sibling-count="2"
rounded="lg"
color="dark"
/>
</template>
<script setup lang="ts">
const route = useRoute()
const router = useRouter()
const page = computed({
get() {
return Number(route.query.page) || 1
},
set(value: number) {
router.replace({ query: { ...route.query, page: value } })
},
})
</script>
Use the rounded prop to change the border radius of the pagination.
<template>
<BasePagination
v-model:page="page"
:items-per-page="8"
:total="512"
:sibling-count="2"
rounded="full"
/>
</template>
<script setup lang="ts">
const route = useRoute()
const router = useRouter()
const page = computed({
get() {
return Number(route.query.page) || 1
},
set(value: number) {
router.replace({ query: { ...route.query, page: value } })
},
})
</script>
Use the size prop to change the size of the pagination buttons.
<template>
<BasePagination
v-model:page="page"
:items-per-page="8"
:total="512"
:sibling-count="2"
size="sm"
/>
</template>
<script setup lang="ts">
const route = useRoute()
const router = useRouter()
const page = computed({
get() {
return Number(route.query.page) || 1
},
set(value: number) {
router.replace({ query: { ...route.query, page: value } })
},
})
</script>
Use the slots to customize the pagination buttons layout. Use the <PaginationItems /> slot to render the pagination items. Use the <PaginationButtonFirst />, <PaginationButtonPrev />, <PaginationButtonNext />, and <PaginationButtonLast /> slots to render the first, previous, next, and last buttons.
<template>
<BasePagination
v-slot="{ items }"
v-model:page="page"
:items-per-page="8"
:total="512"
:sibling-count="2"
size="sm"
class="w-full justify-between"
>
<div class="flex gap-2">
<BasePaginationButtonFirst />
<BasePaginationButtonPrev />
</div>
<BasePaginationItems :items />
<div class="flex gap-2">
<BasePaginationButtonNext />
<BasePaginationButtonLast />
</div>
</BasePagination>
</template>
<script setup lang="ts">
const route = useRoute()
const router = useRouter()
const page = computed({
get() {
return Number(route.query.page) || 1
},
set(value: number) {
router.replace({ query: { ...route.query, page: value } })
},
})
</script>
Use the slots to customize the pagination buttons layout. Use the <page /> slot to render the page number. Use the <ellipsis /> slot to render the ellipsis.
<template>
<BasePagination
v-model:page="page"
:items-per-page="8"
:total="1_000_000"
:sibling-count="1"
rounded="full"
variant="dark"
>
<template #page="{ page }">
{{ formatter.format(page) }}
</template>
<template #ellipsis>
…
</template>
</BasePagination>
</template>
<script setup lang="ts">
const route = useRoute()
const router = useRouter()
const page = computed({
get() {
return Number(route.query.page) || 1
},
set(value: number) {
router.replace({ query: { ...route.query, page: value } })
},
})
const formatter = new Intl.NumberFormat('en-US', { style: 'decimal' })
</script>