Pagination
Browse a dataset by page, with configurable page-size selection and direct page entry.
Import
import { HuiPagination } from '@nscode/handy-ui'
import type {
PaginationProps,
PaginationLayoutItem,
PaginationSize,
PaginationEmits
} from '@nscode/handy-ui'
Basic usage
Bind currentPage and pageSize separately. total determines the number of pages.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiPagination } from '@nscode/handy-ui'
const currentPage = ref(1)
const pageSize = ref(10)
</script>
<template>
<HuiPagination v-model:current-page="currentPage" v-model:page-size="pageSize" :total="100" />
<p style="margin-top: 12px">Current page: {{ currentPage }}; page size: {{ pageSize }}</p>
</template>
Self-managed And Controlled Pages
Omitting currentPage stores the current page internally, starting at one. An update listener alone keeps this behavior. Passing the prop makes it controlled, including undefined, which displays page one. Buttons, the jumper, and range corrections request updates; highlighting, the jumper, and previous/next states use the value accepted by the parent.
Ignored requests keep the original page. If the total decreases and the parent keeps an out-of-range page, no page button is active and the jumper keeps that parent value. Accept the correction and update the query. Removing the prop restores the saved internal page; changing control mode emits a development diagnostic. Adding or removing listeners does not switch modes.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiPagination, HuiSpace } from '@nscode/handy-ui'
const stateBound = ref(2)
const stateRedraw = ref(0)
const stateLast = ref<number | string>('None')
const recordState = (page: number) => {
stateLast.value = page
}
</script>
<template>
<HuiSpace class="pagination-current-q1-demo" direction="vertical" fill :data-parent="stateRedraw">
<HuiSpace wrap>
<HuiButton class="page-redraw" @click="stateRedraw++"
>Redraw parent {{ stateRedraw }}</HuiButton
>
<span>Choose page three, then redraw the parent to compare accepted pages.</span>
</HuiSpace>
<HuiSpace class="page-local" wrap>
<span>Unbound page</span>
<HuiPagination :total="50" layout="prev, pager, next, jumper" />
</HuiSpace>
<HuiSpace class="page-listener" wrap>
<span>Listener only</span>
<HuiPagination
:total="50"
layout="prev, pager, next, jumper"
@update:current-page="recordState"
/>
</HuiSpace>
<HuiSpace class="page-empty" wrap>
<span>Explicit undefined</span>
<HuiPagination :current-page="undefined" :total="50" layout="prev, pager, next, jumper" />
</HuiSpace>
<HuiSpace class="page-fixed" wrap>
<span>Fixed page two; the parent ignores updates</span>
<HuiPagination :current-page="2" :total="50" layout="prev, pager, next, jumper" />
</HuiSpace>
<HuiSpace class="page-bound" wrap>
<span>Two-way binding</span>
<HuiPagination
v-model:current-page="stateBound"
:total="50"
layout="prev, pager, next, jumper"
/>
</HuiSpace>
<span class="page-status">Update request: {{ stateLast }}; bound page: {{ stateBound }}</span>
</HuiSpace>
</template>
Self-managed and controlled page sizes
currentPage and pageSize are independently controlled. Omit pageSize, or only listen to updates, to retain an internal size starting at 10. Passing it, including undefined, makes it controlled; undefined displays 10. Rejected requests do not change page counts or clamp the current page. The example binds currentPage in every row to show accepted clamping.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiPagination, HuiSpace } from '@nscode/handy-ui'
const sizeBound = ref(10)
const sizeRedraw = ref(0)
const sizeLast = ref<number | string>('None')
const sizePages = ref({ local: 9, listener: 9, empty: 9, fixed: 9, bound: 9 })
const recordSize = (size: number) => {
sizeLast.value = size
}
</script>
<template>
<HuiSpace class="pagination-size-q1-demo" direction="vertical" fill :data-parent="sizeRedraw">
<HuiSpace wrap>
<HuiButton class="size-redraw" @click="sizeRedraw++"
>Redraw parent {{ sizeRedraw }}</HuiButton
>
<span>Start on page 9; select 50 items per page and compare actual pages.</span>
</HuiSpace>
<HuiSpace class="size-local" wrap>
<span>Omitted page size</span>
<HuiPagination
v-model:current-page="sizePages.local"
:total="100"
layout="sizes, pager, jumper"
/>
</HuiSpace>
<HuiSpace class="size-listener" wrap>
<span>Update listener only</span>
<HuiPagination
v-model:current-page="sizePages.listener"
@update:page-size="recordSize"
:total="100"
layout="sizes, pager, jumper"
/>
</HuiSpace>
<HuiSpace class="size-empty" wrap>
<span>Explicit undefined</span>
<HuiPagination
v-model:current-page="sizePages.empty"
:page-size="undefined"
:total="100"
layout="sizes, pager, jumper"
/>
</HuiSpace>
<HuiSpace class="size-fixed" wrap>
<span>Fixed 10; parent rejects updates</span>
<HuiPagination
v-model:current-page="sizePages.fixed"
:page-size="10"
:total="100"
layout="sizes, pager, jumper"
/>
</HuiSpace>
<HuiSpace class="size-bound" wrap>
<span>Two-way binding</span>
<HuiPagination
v-model:current-page="sizePages.bound"
v-model:page-size="sizeBound"
:total="100"
layout="sizes, pager, jumper"
/>
</HuiSpace>
<span class="size-status"
>Requested: {{ sizeLast }};Bound size: {{ sizeBound }};Actual pages: {{ sizePages }}</span
>
</HuiSpace>
</template>
Layout
Choose total, sizes, prev, pager, next, and jumper in the desired comma-separated order.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiPagination, HuiSpace } from '@nscode/handy-ui'
const currentPage = ref(1)
</script>
<template>
<HuiSpace direction="vertical" fill>
<div>
<div class="demo-label">prev, pager, next</div>
<HuiPagination v-model:current-page="currentPage" :total="100" layout="prev, pager, next" />
</div>
<div>
<div class="demo-label">total, prev, pager, next</div>
<HuiPagination
v-model:current-page="currentPage"
:total="100"
layout="total, prev, pager, next"
/>
</div>
<div>
<div class="demo-label">sizes, prev, pager, next</div>
<HuiPagination
v-model:current-page="currentPage"
:total="100"
layout="sizes, prev, pager, next"
/>
</div>
<div>
<div class="demo-label">prev, pager, next, jumper</div>
<HuiPagination
v-model:current-page="currentPage"
:total="100"
layout="prev, pager, next, jumper"
/>
</div>
<div>
<div class="demo-label">prev, next (compact)</div>
<HuiPagination v-model:current-page="currentPage" :total="100" layout="prev, next" />
</div>
<div>
<div class="demo-label">pager (page numbers only)</div>
<HuiPagination v-model:current-page="currentPage" :total="100" layout="pager" />
</div>
<div>
<div class="demo-label">jumper, prev, pager, next, total (same display order)</div>
<HuiPagination
v-model:current-page="currentPage"
:total="100"
layout="jumper, prev, pager, next, total"
/>
</div>
</HuiSpace>
</template>
<style scoped>
.demo-label {
margin-bottom: 4px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
</style>
Large page counts
The first and last pages stay visible. Ellipses replace distant page numbers as the current page changes.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiPagination, HuiSpace } from '@nscode/handy-ui'
const currentPage = ref(50)
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace wrap>
<HuiButton size="small" @click="currentPage = 1">Page 1 (ellipsis on the right)</HuiButton>
<HuiButton size="small" @click="currentPage = 50">Page 50 (ellipsis on both sides)</HuiButton>
<HuiButton size="small" @click="currentPage = 100">Page 100 (ellipsis on the left)</HuiButton>
</HuiSpace>
<HuiPagination v-model:current-page="currentPage" :total="1000" layout="prev, pager, next" />
<HuiPagination :total="70" layout="prev, pager, next" />
</HuiSpace>
</template>
Page sizes
Provide pageSizes to choose the available capacities. The current value is included even when absent from that array.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiPagination, HuiSpace } from '@nscode/handy-ui'
const currentPage = ref(10)
const pageSize = ref(20)
const message = ref('')
const handleSizeChange = (size: number) => {
message.value = `sizeChange: page size is ${size}`
}
const otherPage = ref(1)
const otherSize = ref(15)
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiPagination
v-model:current-page="currentPage"
v-model:page-size="pageSize"
:total="235"
:page-sizes="[20, 50, 100]"
layout="total, sizes, prev, pager, next"
@size-change="handleSizeChange"
/>
<p>Page {{ currentPage }}, {{ pageSize }} items per page. {{ message }}</p>
<HuiPagination
v-model:current-page="otherPage"
v-model:page-size="otherSize"
:total="235"
:page-sizes="[10, 20, 50]"
layout="sizes, prev, pager, next"
/>
</HuiSpace>
</template>
Backgrounds
Compare the default appearance with background buttons.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiPagination, HuiSpace } from '@nscode/handy-ui'
const currentPage = ref(3)
</script>
<template>
<HuiSpace direction="vertical" fill>
<div>
<div class="demo-label">Without background</div>
<HuiPagination v-model:current-page="currentPage" :total="100" layout="prev, pager, next" />
</div>
<div>
<div class="demo-label">background</div>
<HuiPagination
v-model:current-page="currentPage"
:total="100"
background
layout="prev, pager, next"
/>
</div>
<div>
<div class="demo-label">background + full layout</div>
<HuiPagination v-model:current-page="currentPage" :total="100" background />
</div>
</HuiSpace>
</template>
<style scoped>
.demo-label {
margin-bottom: 4px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
</style>
Sizes
Compare large, default, and small. Explicit size wins over the deprecated small shortcut, then ConfigProvider provides the fallback.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiPagination, HuiSpace } from '@nscode/handy-ui'
const currentPage = ref(1)
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiSpace wrap>
<span class="row-label">large</span>
<HuiPagination v-model:current-page="currentPage" :total="100" size="large" />
</HuiSpace>
<HuiSpace wrap>
<span class="row-label">default</span>
<HuiPagination v-model:current-page="currentPage" :total="100" />
</HuiSpace>
<HuiSpace wrap>
<span class="row-label">small</span>
<HuiPagination v-model:current-page="currentPage" :total="100" size="small" />
</HuiSpace>
<HuiSpace wrap>
<span class="row-label">large</span>
<HuiPagination
v-model:current-page="currentPage"
:total="100"
size="large"
background
layout="prev, pager, next"
/>
</HuiSpace>
<HuiSpace wrap>
<span class="row-label">default</span>
<HuiPagination
v-model:current-page="currentPage"
:total="100"
background
layout="prev, pager, next"
/>
</HuiSpace>
<HuiSpace wrap>
<span class="row-label">small</span>
<HuiPagination
v-model:current-page="currentPage"
:total="100"
size="small"
background
layout="prev, pager, next"
/>
</HuiSpace>
</HuiSpace>
</template>
<style scoped>
.row-label {
display: inline-block;
width: 56px;
color: var(--hui-text-color-secondary);
font-size: var(--hui-font-size-sm);
}
</style>
Disabled
disabled applies to page buttons, the page-size selector, and the jumper.
<template>
<HuiSpace direction="vertical" fill>
<HuiPagination :current-page="3" :total="100" disabled />
<HuiPagination :current-page="3" :total="100" background disabled layout="prev, pager, next" />
</HuiSpace>
</template>
Hide a single page
hideOnSinglePage removes the whole navigation when there is only one page.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiButton, HuiPagination, HuiSpace } from '@nscode/handy-ui'
const currentPage = ref(1)
const total = ref(5)
</script>
<template>
<HuiSpace direction="vertical" align="start">
<HuiButton @click="total = total > 10 ? 5 : 50">Toggle total (currently {{ total }})</HuiButton>
<HuiPagination
v-model:current-page="currentPage"
:total="total"
hide-on-single-page
layout="total, prev, pager, next"
/>
</HuiSpace>
</template>
Navigation events
Use change and sizeChange to fetch data. The example renders request status and guards stale responses.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiPagination, HuiSpace } from '@nscode/handy-ui'
const currentPage = ref(1)
const pageSize = ref(10)
const status = ref('Choose a page or change page size')
const events = ref<string[]>([])
const record = (text: string) => {
events.value = [text, ...events.value].slice(0, 5)
}
const loadData = () => {
status.value = `Loading page ${currentPage.value}, ${pageSize.value} items per page...`
const page = currentPage.value
window.setTimeout(() => {
if (page === currentPage.value) status.value = `Loaded page ${page}`
}, 500)
}
const handleChange = (page: number) => {
record(`change: ${page}`)
loadData()
}
const handleSizeChange = (size: number) => {
record(`sizeChange: ${size}`)
currentPage.value = 1
loadData()
}
</script>
<template>
<HuiSpace direction="vertical" fill>
<HuiPagination
v-model:current-page="currentPage"
v-model:page-size="pageSize"
:total="200"
@change="handleChange"
@size-change="handleSizeChange"
/>
<p>{{ status }}</p>
<p v-if="events.length">Recent events: {{ events.join(', ') }}</p>
</HuiSpace>
</template>
Form isolation
Page-size and jumper inputs are browsing controls. They ignore outer Form disabled/readonly state, validation, and label registration. The business input below keeps its context; explicit Pagination size and disabled still apply.
<script setup lang="ts">
import { ref } from 'vue'
import { HuiForm, HuiFormItem, HuiInput, HuiSpace, HuiPagination } from '@nscode/handy-ui'
const boundaryPage = ref(1)
const boundaryPageSize = ref(10)
</script>
<template>
<HuiForm disabled readonly size="large">
<HuiFormItem label="Business input">
<HuiSpace direction="vertical" fill>
<HuiPagination
v-model:current-page="boundaryPage"
v-model:page-size="boundaryPageSize"
:total="100"
layout="sizes,prev,pager,next,jumper"
size="small"
/>
<HuiInput model-value="Business value" />
</HuiSpace>
</HuiFormItem>
</HuiForm>
</template>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| total | number | 0 | Total item count. Non-positive totals produce one page. |
| currentPage / v-model:current-page | number | 1 | Passing the prop makes the page controlled, including undefined; omission or a listener alone stores it internally. |
| pageSize / v-model:page-size | number | 10 | Omitted/listener-only retains 10 internally; passing the prop, including undefined, is controlled. Undefined displays 10. Non-positive sizes produce one page. |
| pageSizes | number[] | [10, 20, 30, 40, 50, 100] | Page-size options. The current size is added when it is absent. |
| layout | string | 'total, sizes, prev, pager, next, jumper' | Comma-separated parts, in display order. |
| background | boolean | false | Add backgrounds to page and previous/next buttons. |
| disabled | boolean | false | Disable this pagination, including its internal controls. |
| size | 'large' | 'default' | 'small' | ConfigProvider, then default | Button heights: 40, 32, and 24px. Internal selectors, input, and labels follow. |
| small | boolean | false | Deprecated shorthand for size=small; explicit size wins. |
| hideOnSinglePage | boolean | false | Hide the navigation when there is only one page. |
Events
| Event | Arguments | Description |
|---|---|---|
| update:currentPage | (value: number) | Request the current page, including clamping after the total decreases. |
| update:pageSize | (value: number) | User selected another page size. |
| change | (currentPage: number) | User navigated through page buttons, previous/next, or the jumper; also emitted by the existing total-decrease clamp behavior. |
| sizeChange | (pageSize: number) | User changed the number of items per page. |
The public page-size notification is declared and emitted as sizeChange. Vue templates can still listen with @size-change; render functions use onSizeChange. Only the new declared event is emitted. The original update:pageSize → sizeChange → accepted-size page-clamp order and parameters remain unchanged.
Slots
None. Compose surrounding controls outside Pagination.
Methods
No public methods. Use the page bindings to update displayed state.
Types
type PaginationSize = 'large' | 'default' | 'small'
type PaginationLayoutItem = 'total' | 'sizes' | 'prev' | 'pager' | 'next' | 'jumper'
interface PaginationProps {
total: number
pageSize?: number
currentPage?: number
pageSizes?: number[]
layout?: string
background?: boolean
disabled?: boolean
size?: PaginationSize
/** @deprecated Use size="small". */
small?: boolean
hideOnSinglePage?: boolean
}
PaginationEmits is also exported from the component directory and package entry point.