Search results
Move between server-backed result pages while retaining the current query.
Components / Navigation
Page navigation with buttons or real Vue router links.
Last changed in version 0.14.2: Improve keyboard navigation, action feedback, and selected colors across Vue components.
bunx --bun @getweini/cli@latest add paginationImport the files copied by the install command, then place the component in your Vue template. The text and values in the example belong to your app; change them to fit your task.
<script setup lang="ts">
import { ref } from 'vue'
import Pagination from './components/ui/pagination/Pagination.vue'
const page = ref(4)
const messages = {
navigation: 'Results pages',
previous: 'Previous page',
next: 'Next page',
page: (value: number) => `Go to page ${value}`,
}
</script>
<template>
<Pagination v-model="page" :total-pages="5" :messages="messages" />
</template>The selected-page background slides to the newly selected page, including when the page range or ellipses change, and it stays still when reduced motion is enabled.
Move between server-backed result pages while retaining the current query.
Keep page controls near the table they update.
Each page number and available direction control is a real NuxtLink.
<script setup lang="ts">
import { computed } from 'vue'
import { NuxtLink } from '#components'
import { useRoute } from '#imports'
import Pagination from './components/ui/pagination/index.vue'
const route = useRoute()
const currentPage = computed(() => Number(route.query.page ?? 1))
const messages = {
navigation: 'Results pages',
previous: 'Previous',
next: 'Next',
page: (n: number) => `Page ${n}`,
}
</script>
<template>
<Pagination
:model-value="currentPage"
:total-pages="20"
:messages="messages"
:link-as="NuxtLink"
:page-to="page => ({ query: { ...route.query, page } })"
/>
</template>Supply messages for every button and bind the current page.
<script setup lang="ts">
import { ref } from 'vue'
import Pagination from './components/ui/pagination/Pagination.vue'
const page = ref(1)
const messages = {
navigation: 'Search results pages',
previous: 'Previous page',
next: 'Next page',
page: (n: number) => `Go to page ${n}`,
}
</script>
<template>
<Pagination v-model="page" :total-pages="20" :messages="messages" />
</template>Fewer siblings make the control easier to fit in a narrow results column.
<script setup lang="ts">
import { ref } from 'vue'
import Pagination from './components/ui/pagination/Pagination.vue'
const page = ref(8)
const messages = {
navigation: 'Orders pages',
previous: 'Previous',
next: 'Next',
page: (n: number) => `Page ${n}`,
}
</script>
<template>
<Pagination
v-model="page"
:total-pages="35"
:sibling-count="0"
:boundary-count="1"
:messages="messages"
/>
</template>Every public prop, model, event, slot, and exposed member of the installed Vue parts is listed below. “Not set” means you can leave that value out; “Required” means you must provide it. Native HTML attributes also work where the component uses a native element.
| Name | Type or signature | Default | What it does |
|---|---|---|---|
totalPagesprop | number | Required | Total number of pages available. |
messagesprop | PaginationMessages | Required | Supply the text this component displays for its built-in actions and states. |
siblingCountprop | number | undefined | 1 | Number of pages shown beside the current page. |
boundaryCountprop | number | undefined | 1 | Number of pages kept visible at the beginning and end. |
disabledprop | boolean | undefined | Not set | Prevent interaction and show the disabled state. |
linkAsprop | Component | undefined | Not set | Render available page controls as router links when paired with pageTo. |
pageToprop | ((page: number) => unknown) | undefined | Not set | It renders buttons by default and router links when linkAs and pageTo are provided. |
modelValuemodel | number | undefined | 1 | Current value. Use v-model to keep it in sync with your page. |
update:modelValueevent | [value: number] | — | Requests a new model value from the parent. |
previousslot | ((props: { disabled: boolean; }) => unknown) | undefined | Optional | Content for the previous area of Pagination. |
nextslot | ((props: { disabled: boolean; }) => unknown) | undefined | Optional | Content for the next area of Pagination. |
pageslot | ((props: { page: number; current: boolean; }) => unknown) | undefined | Optional | Content for the page area of Pagination. |
ellipsisslot | (() => unknown) | undefined | Optional | Content for the ellipsis area of Pagination. |
// packages/frameworks/vue/components/pagination/types.ts
// ------- IMPORTS -------
import type { Component } from 'vue'
// ------- TYPES -------
export interface PaginationMessages {
navigation: string
previous: string
next: string
page: (page: number) => string
}
export interface PaginationProps {
totalPages: number
messages: PaginationMessages
siblingCount?: number
boundaryCount?: number
disabled?: boolean
/** Render available page controls as router links when paired with pageTo. */
linkAs?: Component
pageTo?: (page: number) => unknown
}
export type PaginationItem = number | 'ellipsis-start' | 'ellipsis-end'