Components/Pagination

Pagination

A control for moving between pages of data.

VerifiedSince 0.3.4
<script>
import { ref } from 'vue'
const page = ref(1)
</script>

Usage

Basic

total and pageSize set the page count; show-info adds page info and show-first-last adds first and last buttons.

Loading demo...

Page Size

page-sizes adds a size selector after the page buttons. Changing the size leaves the page alone; the host decides whether to return to page 1.

Loading demo...

Data Operations

Place pagination right below the table, bound to the same reactive state as filtering and selection.

With DataTable and Skeleton

Loading demo...

Best Practices

  • Prefer total with pageSize; use totalPages only when the backend returns a page count alone.
  • Keep currentPage one-based and initialize it to 1.
  • Reset currentPage to 1 when filters, search terms, or the page size change.
  • Use pageSizes instead of your own size select: it is named by a visible label and shares the pagination's row.
  • Use the info slot for localized range copy, such as "Viewing 21–40 of 120 items".

API Reference

Props

PropertyTypeDefaultDescription
currentPageCurrent page, counted from 1
pageSizeItems per page; pair with v-model:page-size when the reader can change it
pageSizesSize choices that render a size selector; invalid sizes are dropped, and a missing pageSize joins them
pageSizeLabelVisible label before the size selector; also names the selector
total-Total item count; when omitted or 0, totalPages is used instead
totalPages-Explicit page count, used when total is not provided
prevIconPrevious-page icon class rendered by TxIcon; empty uses the built-in chevron
nextIconNext-page icon class rendered by TxIcon; empty uses the built-in chevron
showInfoShows page and total info
showFirstLastShows first and last buttons
ariaLabelThe aria-label of the root nav landmark
firstLabelThe first-page button's aria-label
prevLabelThe previous-page button's aria-label
nextLabelThe next-page button's aria-label
lastLabelThe last-page button's aria-label

Events

PropertyTypeDefaultDescription
update:currentPage-Current-page update (v-model)
pageChange-Fires when the user moves to another page
update:pageSize-Page-size update (v-model) when the reader picks another size; the page is unchanged
pageSizeChange-Fires when the reader picks another page size

Slots

PropertyTypeDefaultDescription
info-Custom page info area

Overview

  • The page count comes from total and pageSize; when total is omitted or 0, totalPages is used.
  • When currentPage falls out of range, the component emits update:currentPage with the nearest valid page.
  • The active page button has aria-current="page"; previous, next, first, and last buttons have readable aria-labels and disable at the boundaries.
  • The size selector renders only with valid pageSizes, and its combobox is named by the visible label through aria-labelledby; otherwise the DOM is unchanged.
  • Picking a different size emits update:pageSize, then pageSizeChange, and leaves the page alone.
  • The on-demand style plugin loads the selector's styles too; manual style imports also need select/style.css and its dependencies.

Technologies

  • Source: packages/tuffex/packages/components/src/pagination/.
查看源码
packages/tuffex/packages/components/src/pagination/index.ts