当前位置: 首页 > 文档资料 > Vant 中文文档 >

Pagination 分页

优质
小牛编辑
123浏览
2023-12-01

引入

import { createApp } from 'vue';
import { Pagination } from 'vant';

const app = createApp();
app.use(Pagination);

代码演示

基础用法

通过 v-model 来绑定当前页码。

<van-pagination v-model="currentPage" :total-items="24" :items-per-page="5" />
export default {
  data() {
    return {
      currentPage: 1,
    };
  },
};

简单模式

mode 设置为 simple 来切换到简单模式,此时分页器不会展示具体的页码按钮。

<van-pagination v-model="currentPage" :page-count="12" mode="simple" />

显示省略号

设置 force-ellipses 后会展示省略号按钮,点击后可以快速跳转。

<van-pagination
  v-model="currentPage"
  :total-items="125"
  :show-page-size="3"
  force-ellipses
/>

自定义按钮

通过 prev-textnext-text 等插槽来自定义分页按钮的内容。

<van-pagination v-model="currentPage" :total-items="50" :show-page-size="5">
  <template #prev-text>
    <van-icon name="arrow-left" />
  </template>
  <template #next-text>
    <van-icon name="arrow" />
  </template>
  <template #page="{ text }">{{ text }}</template>
</van-pagination>

API

Props

参数说明类型默认值
v-model当前页码number-
mode显示模式,可选值为 simplestringmulti
prev-text上一页按钮文字string上一页
next-text下一页按钮文字string下一页
page-count总页数number / string根据页数计算
total-items总记录数number / string0
items-per-page每页记录数number / string10
show-page-size显示的页码个数number / string5
force-ellipses是否显示省略号booleanfalse

Events

事件名说明回调参数
change页码改变时触发-

Slots

名称描述参数
page v2.10.9自定义页码{ number: number, text: string, active: boolean }
prev-text v2.10.9自定义上一页按钮文字-
next-text v2.10.9自定义下一页按钮文字-