1.0.3 • Published 1 month ago

@tanzhenxing/zx-pagination v1.0.3

Weekly downloads
-
License
ISC
Repository
-
Last release
1 month ago

zx-pagination 分页组件

一个功能完善的分页组件,支持多种布局组合和样式定制。

基本用法

<template>
  <zx-pagination
    v-model:current-page="currentPage"
    v-model:page-size="pageSize"
    :total="total"
    @current-change="handleCurrentChange"
  />
</template>

<script setup>
import { ref } from 'vue'

const currentPage = ref(1)
const pageSize = ref(10)
const total = ref(100)

const handleCurrentChange = (page) => {
  console.log(`当前页: ${page}`)
}
</script>

不同尺寸

<template>
  <zx-pagination :total="50" size="small" />
  <zx-pagination :total="50" />
  <zx-pagination :total="50" size="large" />
</template>

带背景色的分页

<template>
  <zx-pagination :total="50" background />
</template>

完整功能示例

<template>
  <zx-pagination
    v-model:current-page="currentPage"
    v-model:page-size="pageSize"
    :total="total"
    :page-sizes="[10, 20, 30, 50]"
    :background="true"
    layout="total, prev, pager, next, jumper"
    @size-change="handleSizeChange"
    @current-change="handleCurrentChange"
  />
</template>

<script setup>
import { ref } from 'vue'

const currentPage = ref(1)
const pageSize = ref(10)
const total = ref(100)

const handleSizeChange = (size) => {
  console.log(`每页 ${size} 条`)
}

const handleCurrentChange = (page) => {
  console.log(`当前页: ${page}`)
}
</script>

属性

属性说明类型可选值默认值
size分页组件大小Stringlarge/default/smalldefault
background是否为分页按钮添加背景色Booleanfalse
page-size每页显示条目个数Number10
default-page-size每页默认的条目个数Number10
total总条目数Number0
page-count总页数,与 total 设置任意一个就可以达到显示页码的功能Number0
pager-count页码按钮的数量,当总页数超过该值时会折叠Number大于等于 5 且小于等于 21 的奇数7
current-page当前页数Number1
default-current-page当前页数的默认值Number1
layout组件布局,子组件名用逗号分隔Stringsizes, prev, pager, next, jumper, ->, totalprev, pager, next, jumper, ->, total
page-sizes每页显示个数选择器的选项设置Array10, 20, 30, 40, 50, 100
prev-text替代图标显示的上一页文字String""
next-text替代图标显示的下一页文字String""
disabled是否禁用分页Booleanfalse
hide-on-single-page只有一页时是否隐藏Booleanfalse

事件

事件名称说明回调参数
update:current-page当前页改变时触发(支持 v-model:current-page)新的页码
update:page-size每页条数改变时触发(支持 v-model:page-size)新的每页条数
size-change每页条数改变时触发新的每页条数
current-change当前页改变时触发新的页码
prev-click点击上一页按钮时触发新的页码
next-click点击下一页按钮时触发新的页码
change当前页码或每页条数变化时触发当前页码, 当前每页条数

布局

通过设置 layout 属性,可以灵活地组合分页组件的各个部分:

  • total: 显示总条目数
  • sizes: 每页显示条目数选择器
  • prev: 上一页按钮
  • pager: 页码按钮
  • next: 下一页按钮
  • jumper: 跳转页码输入框
  • ->: 右对齐分隔符,右侧内容将右对齐