Pagination 分页
基础用法
使用 v-model / modelValue
快速绑定当前页码。
控制台
currentPage: 1
total: 100
查看代码
vue
<template>
<demo-container>
<gov-pagination v-model="currentPage" :total="total" />
<template #console>
currentPage: {{ currentPage }} <br />
total: {{ total }} <br />
</template>
</demo-container>
</template>
<script setup>
import { ref } from "vue";
const currentPage = ref(1);
const total = ref(100);
</script>
设置分页
可以通过 v-model:page-size
设置当前分页大小(对应下拉框值);通过设置 page-sizes
可设置分页大小选择器内的 options
。
控制台
pageSize: 20
pageSizes: [
20,
40,
60
]
currentPage: 1
total: 100
查看代码
vue
<template>
<demo-container>
<gov-pagination
v-model="currentPage"
v-model:page-size="pageSize"
:total="total"
:page-sizes="pageSizes"
/>
<template #console>
pageSize: {{ pageSize }} <br />
pageSizes: {{ pageSizes }} <br />
currentPage: {{ currentPage }} <br />
total: {{ total }} <br />
</template>
</demo-container>
</template>
<script setup>
import { ref } from "vue";
const pageSize = ref(20);
const pageSizes = ref([20, 40, 60]);
const currentPage = ref(1);
const total = ref(100);
</script>
朴素模式
朴素模式只有简单的分页分页列表、前一页、后一页;
控制台
currentPage: 1
total: 100
查看代码
vue
<template>
<demo-container>
<gov-pagination plain v-model="currentPage" :total="total" />
<template #console>
currentPage: {{ currentPage }} <br />
total: {{ total }} <br />
</template>
</demo-container>
</template>
<script setup>
import { ref } from "vue";
const currentPage = ref(1);
const total = ref(100);
</script>
禁用模式
禁用时分页不可选择。
控制台
currentPage: 1
total: 100
查看代码
vue
<template>
<demo-container>
<gov-pagination
plain
disabled
v-model="currentPage"
:total="total"
/>
<hr />
<gov-pagination
disabled
v-model="currentPage"
:total="total"
/>
<template #console>
currentPage: {{ currentPage }} <br />
total: {{ total }} <br />
</template>
</demo-container>
</template>
<script setup>
import { ref } from "vue";
const currentPage = ref(1);
const total = ref(100);
</script>
背景色
设置背景色风格。
控制台
currentPage: 1
total: 100
查看代码
vue
<template>
<demo-container>
<gov-pagination plain background v-model="currentPage" :total="total" />
<hr />
<gov-pagination background v-model="currentPage" :total="total" />
<template #console>
currentPage: {{ currentPage }} <br />
total: {{ total }} <br />
</template>
</demo-container>
</template>
<script setup>
import { ref } from "vue";
const currentPage = ref(1);
const total = ref(100);
</script>
自定义
自定义上下页。
控制台
currentPage: 1
total: 100
查看代码
vue
<template>
<demo-container>
<gov-pagination v-model="currentPage" :total="total">
<template #prev>上一页</template>
<template #next>下一页</template>
</gov-pagination>
<template #console>
currentPage: {{ currentPage }} <br />
total: {{ total }} <br />
</template>
</demo-container>
</template>
<script setup>
import { ref } from "vue";
const currentPage = ref(1);
const total = ref(100);
</script>
Attributes
属性名 | 说明 | 类型 | 可选值 | 默认值 |
---|---|---|---|---|
modelValue(v-model) | 当前页码 | Number | — | 1 |
pageSize(v-model:pageSize) | 每页显示条数 | Number | — | 10 |
pageSizes | 每页大小选项数组 | Array | — | [10, 20, 30, 40] |
disabled | 是否禁用分页 | Boolean | true, false | false |
background | 是否显示背景 | Boolean | true, false | false |
plain | 是否为朴素模式 | Boolean | true, false | false |
total | 总条数 | Number | — | 0 |
Events
事件名 | 说明 | 回调参数 |
---|---|---|
update:modelValue | 当前页码改变时触发 | 新的页码 |
update:pageSize | 每页大小改变时触发 | 新的每页大小 |
sizeChange | 每页大小改变时触发 | 新的每页大小 |
currentChange | 当前页码改变时触发 | 新的页码 |
Slots
插槽名 | 说明 | 作用域插槽 | 内容 |
---|---|---|---|
total | 自定义总条数显示 | 是 | 可以自定义总条数的显示方式,提供了 total 作为作用域插槽属性 |
prev | 自定义上一页按钮内容 | 否 | 可以自定义上一页按钮的内容 |
next | 自定义下一页按钮内容 | 否 | 可以自定义下一页按钮的内容 |