Skip to content

Pagination

When there is too much data, use pagination to decompose the data.

Component Types

Basic Usage

Use v-model to bind the current page number, total to set the total number of items, and page-size to set the number of items displayed per page (default is 10). The total number of pages is automatically calculated based on total and page-size.

html
<wd-pagination v-model="value" :total="190" @change="handleChange" />
typescript
const value = ref<number>(1)
function handleChange({ value }) {
  console.log(value)
}

Component Variants

Button Style

Set the button style via button-variant, optional values are text, plain, dashed, base.

html
<wd-pagination v-model="value1" :total="190" button-variant="plain" />
<wd-pagination v-model="value2" :total="190" button-variant="dashed" />
<wd-pagination v-model="value3" :total="190" button-variant="base" />

Icon

Set the show-icon property to display pagination navigation as Icon icons.

html
<wd-pagination v-model="value" :total="19" @change="handleChange" show-icon />

Text Hint

Set the show-message property to display text hints.

html
<wd-pagination 
  v-model="value" 
  :total="total" 
  :page-size="pageSize" 
  @change="handleChange" 
  show-icon 
  show-message
/>
typescript
const value = ref<number>(1)
const total = ref<number>(160)
const pageSize = ref<number>(20)

Content Forms

Custom Slots

The component provides four slots: prev, size, next, and message, which can be used to customize pagination buttons, middle page number information, and bottom hints.

html
<wd-pagination v-model="value" :total="190" show-message>
  <template #prev="{ modelValue }">
    <wd-button :disabled="modelValue <= 1" size="small" type="danger" @click="value -= 1">Previous</wd-button>
  </template>
  <template #next="{ modelValue, totalPageNum }">
    <wd-button :disabled="modelValue >= totalPageNum" size="small" type="danger" @click="value += 1">Next</wd-button>
  </template>
  <template #size="{ modelValue, totalPageNum }">
    <view class="custom-pagination__content">
      <text class="custom-pagination__page">{{ modelValue }}</text>
      <text class="custom-pagination__separator">/</text>
      <text class="custom-pagination__total">{{ totalPageNum }}</text>
    </view>
  </template>
  <template #message="{ total }">
    <view class="custom-pagination__message">Current page {{ value }}, total {{ total }} items</view>
  </template>
</wd-pagination>
scss
.custom-pagination__content {
  display: flex;
  justify-content: center;
  align-items: center;
  flex: 1;
}

.custom-pagination__page {
  color: #f00;
}

.custom-pagination__separator {
  margin: 0 5px;
}

.custom-pagination__total {
  color: #00f;
}

.custom-pagination__message {
  margin-top: 10px;
  color: #999;
  text-align: center;
}

Attributes

ParameterDescriptionTypeDefault Value
v-modelCurrent page numbernumber-
total-pageTotal number of pages; when total is passed, it will be calculated based on total and page-sizenumber1
totalTotal number of data itemsnumber0
page-sizeNumber of items per pagenumber10
prev-textPrevious page button text; when not set, uses built-in internationalized textstring-
next-textNext page button text; when not set, uses built-in internationalized textstring-
show-iconWhether to show page turn iconsbooleanfalse
show-messageWhether to show text hintsbooleanfalse
button-variantPagination button style, optional values are base, plain, dashed, textButtonVarianttext
hide-if-one-pageWhether to hide when total pages is only one pagebooleanfalse
custom-classRoot node custom class namestring''
custom-styleRoot node custom stylestring''

Events

Event NameDescriptionParameters
changeTriggered when page number changes{ value }
update:modelValueTriggered when v-model updatesvalue: number

Slots

NameDescriptionParameters
prevCustom previous page button{ modelValue, totalPageNum, total, pageSize }
sizeCustom middle page number display area{ modelValue, totalPageNum, total, pageSize }
nextCustom next page button{ modelValue, totalPageNum, total, pageSize }
messageCustom bottom hint message, only effective when show-message is true{ modelValue, totalPageNum, total, pageSize }

External Classes

Class NameDescription
custom-classRoot node style

主题定制

CSS 变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 全局配置

名称默认值描述
--wot-pagination-bg$filled-oppo分页背景色
--wot-pagination-padding$padding-loose分页内边距
--wot-pagination-icon-size$n-16分页图标尺寸
--wot-pagination-message-color$text-secondary辅助文案颜色
--wot-pagination-message-font-size$typography-body-size-main辅助文案字号
--wot-pagination-message-line-height$typography-body-line--height-size-main辅助文案行高
--wot-pagination-message-margin-top$spacing-super-tight辅助文案顶部间距
--wot-pagination-nav-width$n-64翻页按钮最小宽度
--wot-pagination-size-font-size$typography-title-size-main页码字号
--wot-pagination-size-line-height$typography-title-line--height-size-main页码行高
--wot-pagination-size-color$text-main页码颜色
--wot-pagination-size-current-color$primary-6当前页码颜色
--wot-pagination-size-separator-margin$spacing-zero $spacing-super-tight分隔符外边距

Source Code

Documentation
Component

Released under the MIT License.

Released under the MIT License.