Skip to content

Pagination 分页

当数据量过多时,使用分页分解数据。

组件类型

基本用法

通过 v-model 来绑定当前页码,total设置总条数,page-size设置一页展示条数,默认为10条,总页数通过totalpage-size自动计算。

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

组件变体

按钮风格

通过 button-variant 设置按钮风格,可选值为 textplaindashedbase

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 图标

设置 show-icon 属性,将分页导航展示为Icon图标。

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

文字提示

设置 show-message 属性,展示文字提示。

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)

内容形态

自定义插槽

组件提供 prevsizenextmessage 四个插槽,可用于自定义分页按钮、中间页码信息和底部提示。

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">上一页</wd-button>
  </template>
  <template #next="{ modelValue, totalPageNum }">
    <wd-button :disabled="modelValue >= totalPageNum" size="small" type="danger" @click="value += 1">下一页</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">当前第{{ value }}页,共{{ total }}条数据</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

参数说明类型默认值
v-model当前页码number-
total-page总页数;传入 total 时会优先根据 totalpage-size 计算number1
total总数据条数number0
page-size每页条数number10
prev-text上一页按钮文字;未设置时使用内置国际化文案string-
next-text下一页按钮文字;未设置时使用内置国际化文案string-
show-icon是否展示翻页图标booleanfalse
show-message是否展示文字提示booleanfalse
button-variant分页按钮风格,可选值为 baseplaindashedtextButtonVarianttext
hide-if-one-page总页数只有一页时是否隐藏booleanfalse
custom-class根节点自定义类名string''
custom-style根节点自定义样式string''

Events

事件名称说明参数
change页码变化时触发{ value }
update:modelValuev-model 更新时触发value: number

Slots

name说明参数
prev自定义上一页按钮{ modelValue, totalPageNum, total, pageSize }
size自定义中间页码显示区域{ modelValue, totalPageNum, total, pageSize }
next自定义下一页按钮{ modelValue, totalPageNum, total, pageSize }
message自定义底部提示信息,仅在 show-messagetrue 时生效{ modelValue, totalPageNum, total, pageSize }

外部样式类

类名说明
custom-class根节点样式

主题定制

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分隔符外边距

源代码

文档
组件

Released under the MIT License.

Released under the MIT License.