|
| 1 | +# Pagination 分页 |
| 2 | + |
| 3 | +当数据量过多时,使用分页分批次加载数据。 |
| 4 | + |
| 5 | +## 演示 |
| 6 | + |
| 7 | +<script setup> |
| 8 | + import { Pagination, Switch, FormItem } from "../../src" |
| 9 | + import { ref, watch } from 'vue' |
| 10 | + |
| 11 | + const singleHide = ref(false) |
| 12 | +</script> |
| 13 | + |
| 14 | +### 基础用法 |
| 15 | + |
| 16 | +只需要传递 `total` 或者 `page-count` 就能显示一个分页组件. 在 `change` 事件中进行分页处理. |
| 17 | + |
| 18 | +<ClientOnly> |
| 19 | + <CodePreview> |
| 20 | + <textarea lang="vue"> |
| 21 | + <script setup lang="ts"> |
| 22 | + function handlePageChange(currentPage: number) { |
| 23 | + console.log(currentPage) |
| 24 | + } |
| 25 | + </script> |
| 26 | + <template> |
| 27 | + <nt-pagination :total="100" @change="handlePageChange"></nt-pagination> |
| 28 | + </template> |
| 29 | + </textarea> |
| 30 | + <template #preview> |
| 31 | + <Pagination :total="100"></Pagination> |
| 32 | + </template> |
| 33 | + </CodePreview> |
| 34 | +</ClientOnly> |
| 35 | + |
| 36 | +### 对齐方式 |
| 37 | + |
| 38 | +通过 `align` 可以设置对齐方式,取值有: `start`**默认**、`center`、`end` |
| 39 | + |
| 40 | +<ClientOnly> |
| 41 | + <CodePreview> |
| 42 | + <textarea lang="vue-html"> |
| 43 | + <nt-pagination :total="100" align="start"></nt-pagination> |
| 44 | + <hr /> |
| 45 | + <nt-pagination :total="100" align="center"></nt-pagination> |
| 46 | + <hr /> |
| 47 | + <nt-pagination :total="100" align="end"></nt-pagination> |
| 48 | + </textarea> |
| 49 | + <template #preview> |
| 50 | + <Pagination :total="100" align="start"></Pagination> |
| 51 | + <hr /> |
| 52 | + <Pagination :total="100" align="center"></Pagination> |
| 53 | + <hr /> |
| 54 | + <Pagination :total="100" align="end"></Pagination> |
| 55 | + </template> |
| 56 | + </CodePreview> |
| 57 | +</ClientOnly> |
| 58 | + |
| 59 | +### 单页隐藏 |
| 60 | + |
| 61 | +当只有一页时,通过 `single-hide` 配置隐藏分页 |
| 62 | + |
| 63 | +<ClientOnly> |
| 64 | + <CodePreview> |
| 65 | + <textarea lang="vue"> |
| 66 | + <script setup lang="ts"> |
| 67 | + const singleHide = ref(false) |
| 68 | + </script> |
| 69 | + <template> |
| 70 | + <nt-form-item label="单页隐藏"> |
| 71 | + <nt-switch v-model="singleHide" /> |
| 72 | + </nt-form-item> |
| 73 | + <hr /> |
| 74 | + <nt-pagination :page-count="1" :hide-on-single-page="singleHide"></nt-pagination> |
| 75 | + </template> |
| 76 | + </textarea> |
| 77 | + <template #preview> |
| 78 | + <FormItem label="单页隐藏"> |
| 79 | + <Switch v-model="singleHide" /> |
| 80 | + </FormItem> |
| 81 | + <hr /> |
| 82 | + <Pagination :page-count="1" :hide-on-single-page="singleHide"></Pagination> |
| 83 | + </template> |
| 84 | + </CodePreview> |
| 85 | +</ClientOnly> |
| 86 | + |
| 87 | +### 简单分页 |
| 88 | + |
| 89 | +简单的分页,在空间有限的情况下,可以使用简单分页。 |
| 90 | + |
| 91 | +<ClientOnly> |
| 92 | + <CodePreview> |
| 93 | + <textarea lang="vue-html"> |
| 94 | + <nt-pagination :page-count="100" simple></nt-pagination> |
| 95 | + </textarea> |
| 96 | + <template #preview> |
| 97 | + <Pagination :page-count="100" simple></Pagination> |
| 98 | + </template> |
| 99 | + </CodePreview> |
| 100 | +</ClientOnly> |
| 101 | + |
| 102 | +## API |
| 103 | + |
| 104 | +### Pagination Props |
| 105 | + |
| 106 | +<!-- prettier-ignore --> |
| 107 | +| 参数 | 说明 | 类型 | 默认值 | |
| 108 | +| --- | --- | --- | --- | |
| 109 | +| `total` | 数据总数 | `number` | - | |
| 110 | +| `page-count` | 页码总数, `total` 和 `page-count` 设置任意一个就可以达到显示页码的功能 | `number` | - | |
| 111 | +| `page-size` | 每页的数据条数 | `number` | `10` | |
| 112 | +| `default-current-page` | 当前页数的默认初始值,不设置时默认为 1 | `number` | `1` | |
| 113 | +| `align` | 对齐方式 | `start \| center \| end` | `start` | |
| 114 | +| `hide-on-single-page` | 只有一页时是否隐藏分页器 | `boolean` | `false` | |
| 115 | +| `simple` | 简单分页 | `boolean` | `false` | |
| 116 | +| `page \| v-model:page` | 当前页数[受控模式] | `number` | - | |
| 117 | + |
| 118 | +### Pagination Emits |
| 119 | + |
| 120 | +<!-- prettier-ignore --> |
| 121 | +| 事件名 | 说明 | 回调参数 | |
| 122 | +| --- | --- | --- | |
| 123 | +| `change` | 当前页改变时触发 | `currentPage: number` | |
0 commit comments