Skip to content

Pagination 分页器

数据量过多时,采用分页的形式将数据分隔,每次只加载一个页面。

导入

js
import Pagination from '@/components/nav/Pagination.vue';

使用方法

基础用法

通过 pageCount 属性设置总页数,使用 v-model:currentPage 绑定当前页码。

vue
<template>
  <Pagination :pageCount="10" v-model:currentPage="page" />
</template>

<script setup>
import { ref } from 'vue';
import Pagination from '@/components/nav/Pagination.vue';

const page = ref(1);
</script>

简单模式

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

vue
<template>
  <Pagination :pageCount="10" simple v-model:currentPage="page" />
</template>

<script setup>
import { ref } from 'vue';
import Pagination from '@/components/nav/Pagination.vue';

const page = ref(1);
</script>

自定义样式

可以设置条目的自定义样式。

vue
<template>
  <Pagination 
    v-model:currentPage="page" 
    :pageCount="10" 
    :buttonStyle="{
      borderRadius: '50rpx',
      margin: '0 4rpx',
    }"
  />
</template>

<script setup>
import { ref } from 'vue';
import Pagination from '@/components/nav/Pagination.vue';

const page = ref(1);
</script>

自定义渲染

允许自定义渲染按钮。

vue
<template>
  <Pagination 
    v-model:currentPage="page"
    :pageCount="10" 
  >
    <template #prev="{ touchable, onClick }">
      <IconButton icon="direction-left" :disabled="!touchable" @click="onClick" />
    </template>
    <template #item="{ text, active, onClick }">
      <Button 
        :text="text" 
        :disabled="active"
        :type="active ? 'primary' : 'warning'"
        size="small"
        round
        @click="onClick" 
      />
    </template>
    <template #next="{ touchable, onClick }">
      <IconButton icon="direction-right" :disabled="!touchable" @click="onClick" />
    </template>
  </Pagination>
</template>

<script setup>
import { ref } from 'vue';
import Pagination from '@/components/nav/Pagination.vue';
import IconButton from '@/components/basic/IconButton.vue';
import Button from '@/components/basic/Button.vue';

const page = ref(1);
</script>

API 参考

Props

名称说明类型必填默认值
v-model:currentPage当前的页码number1
pageCount总共有的页数number1
showNextPrev是否显示上一页下一页按钮booleantrue
showPageCount同时显示的页面按钮数量number5
simple是否简单模式booleanfalse
prevText上一页按钮文字string'上一页'
nextText下一页按钮文字string'下一页'
pressedColor按钮按下颜色string'pressed.white'
pressedTextColor按钮按下时文字的颜色string'text.second'
activeColor按钮激活时(为当前页码)颜色string'primary'
deactiveColor按钮为非当前页码下颜色string'white'
activeTextColor按钮激活时(为当前页码)文字颜色string'white'
deactiveTextColor按钮为非当前页码下文字颜色string'text.content'
buttonStyle自定义按钮样式ViewStyle-
textStyle自定义文字样式TextStyle-

Slots

名称说明参数
prev自定义上一页按钮{ onClick: Function, touchable: boolean }
next自定义下一页按钮{ onClick: Function, touchable: boolean }
item自定义页码按钮{ text: string, index: number, active: boolean, onClick: Function }
simple简单模式下的文本{ text: string }

Events

名称说明参数
update:currentPage页码改变时触发新的页码数值

主题变量

变量名默认值说明
PaginationPressedColorpressed.white按钮按下颜色
PaginationPressedTextColortext.second按钮按下时文字颜色
PaginationActiveColorprimary按钮激活时颜色
PaginationDeactiveColorwhite按钮非激活时颜色
PaginationActiveTextColorwhite按钮激活时文字颜色
PaginationDeactiveTextColortext.content按钮非激活时文字颜色