Pagination 分页
介绍
数据量过多时,采用分页的形式将数据分隔,每次只加载一个页面。
引入
ts
import { IBestPagination } from "@ibestservices/ibest-ui-v2";
代码演示
基础用法
点我查看代码
ts
@Entry
@ComponentV2
struct DemoPage {
@Local currentPage: number = 1
build() {
Column() {
IBestPagination({
currentPage: this.currentPage!!,
totalItems: 24,
itemsPerPage: 5,
onChange: (value: number) => {
console.log('当前页码:', value)
}
})
}
}
}
简单模式
点我查看代码
ts
@Entry
@ComponentV2
struct DemoPage {
@Local currentPage: number = 1
build() {
Column() {
IBestPagination({
currentPage: this.currentPage!!,
pageCount: 12,
mode: 'simple'
})
}
}
}
自定义样式
点我查看代码
ts
@Entry
@ComponentV2
struct DemoPage {
@Local currentPage: number = 1
build() {
Column() {
IBestPagination({
currentPage: this.currentPage!!,
totalItems: 24,
itemsPerPage: 5,
textColor: "#ddd",
bgColor: "#13ce66",
activeBgColor: "#f56c6c"
})
}
}
}
显示省略号
点我查看代码
ts
@Entry
@ComponentV2
struct DemoPage {
@Local currentPage: number = 1
build() {
Column() {
IBestPagination({
currentPage: this.currentPage!!,
totalItems: 125,
showPageSize: 3,
forceEllipses: true
})
}
}
}
自定义按钮
点我查看代码
ts
@Entry
@ComponentV2
struct DemoPage {
@Local currentPage: number = 1
build() {
Column() {
IBestPagination({
currentPage: this.currentPage!!,
totalItems: 125,
showPageSize: 5,
prevText: 'prev',
nextText: 'next'
})
}
}
}
API
@Props
参数 | 说明 | 类型 | 默认值 |
---|---|---|---|
currentPage | 当前页码, 支持双向绑定 | number | '' |
mode | 分页显示模式, 可选值 simple 、multi | string | multi |
prevText | 上一页按钮文本 | ResourceStr | 上一页 |
nextText | 下一页按钮文本 | ResourceStr | 下一页 |
textColor | 文本颜色 | ResourceColor | #1989fa |
activeTextColor | 文本选中颜色 | ResourceColor | #fff |
disabledTextColor | 文本禁用颜色 | ResourceColor | #646566 |
bgColor | 背景颜色 | ResourceColor | #fff |
activeBgColor | 背景选中颜色 | ResourceColor | #1989fa |
disabledBgColor | 背景禁用颜色 | ResourceColor | #f7f8fa |
bdColor | 边框颜色 | ResourceColor | #f5f5f7 |
pageCount | 总页数 | number | string | '' |
totalItems | 总数量 | number | string | '' |
showPageSize | 每页显示页码数 | number | string | 5 |
itemsPerPage | 每页条目数 | number | string | 10 |
forceEllipses | 是否显示省略号 | boolean | false |
showPrevButton | 是否显示上一页按钮 | boolean | true |
showNextButton | 是否显示下一页按钮 | boolean | true |
Events
事件名 | 说明 | 回调参数 |
---|---|---|
onChange | 页码变化时触发 | page: number |