Pagination分页

Pagination 分页

采用分页的形式分隔长列表,每次只加载一个页面。

代码演示

-

  • 1

  • 2

  • 3

  • 4

  • 5

-

基本

基础分页。

<​template>  <​a-pagination v-model:current="current" :total="50" show-less-items /><​/template><​script lang="ts">import { defineComponent } from 'vue';export default defineComponent({  setup() {    return {      current: 2,    };  },});<​/script>

-

  • 1

- •••

- 4

  • 5

  • 6

  • 7

  • 8

- •••

- 50

-

更多

更多分页。

<​template>  <​a-pagination v-model:current="current" :total="500" /><​/template><​script lang="ts">import { defineComponent } from 'vue';export default defineComponent({  setup() {    return {      current: 6,    };  },});<​/script>

改变

改变每页显示条目数。

<​template>  <​div>    <​a-pagination      show-size-changer      v-model:current="current1"      v-model:pageSize="pageSize"      :total="500"      @showSizeChange="onShowSizeChange"    />    <​br />    <​a-pagination      v-model:current="current2"      show-size-changer      :total="500"      disabled      @showSizeChange="onShowSizeChange"    />  <​/div><​/template><​script lang="ts">import { defineComponent, ref, watch } from 'vue';export default defineComponent({  setup() {    const pageSize = ref(20);    const current1 = ref(3);    const current2 = ref(4);    const onShowSizeChange = (current: number, pageSize: number) => {      console.log(current, pageSize);    };    watch(pageSize, () => {      console.log('pageSize', pageSize.value);    });    watch(current1, () => {      console.log('current', current1.value);    });    return {      pageSize,      current1,      current2,      onShowSizeChange,    };  },});<​/script>

-

  • 1

  • 2

  • 3

  • 4

  • 5

-

- 10条/页

自定义下拉选项

自定义下拉选项,例如添加全部选项

<​template>  <​a-pagination    v-model:current="current"    :page-size-options="pageSizeOptions"    :total="total"    show-size-changer    :page-size="pageSize"    @showSizeChange="onShowSizeChange"  >    <​template #buildOptionText="props">      <​span v-if="props.value !== '50'">{{ props.value }}条/页<​/span>      <​span v-else>全部<​/span>    <​/template>  <​/a-pagination><​/template><​script lang="ts">import { defineComponent, ref } from 'vue';export default defineComponent({  setup() {    const pageSizeOptions = ref<​string[]>(['10', '20', '30', '40', '50']);    const current = ref(1);    const pageSizeRef = ref(10);    const total = ref(50);    const onShowSizeChange = (current: number, pageSize: number) => {      console.log(pageSize);      pageSizeRef.value = pageSize;    };    return {      pageSizeOptions,      current,      pageSize: pageSizeRef,      total,      onShowSizeChange,    };  },});<​/script>

跳转

快速跳转到某一页。

<​template>  <​div>    <​a-pagination show-quick-jumper v-model:current="current1" :total="500" @change="onChange" />    <​br />    <​a-pagination      show-quick-jumper      v-model:current="current2"      :total="500"      disabled      show-less-items      @change="onChange"    />  <​/div><​/template><​script lang="ts">import { defineComponent, ref } from 'vue';export default defineComponent({  setup() {    const current1 = ref<​number>(1);    const current2 = ref<​number>(2);    const onChange = (pageNumber: number) => {      console.log('Page: ', pageNumber);    };    return {      current1,      current2,      onChange,    };  },});<​/script>

迷你

迷你版本。

<​template>  <​div id="components-pagination-demo-mini">    <​a-pagination size="small" :total="50" />    <​a-pagination size="small" :total="50" show-size-changer show-quick-jumper />    <​a-pagination size="small" :total="50" :show-total="total => `Total ${total} items`" />  <​/div><​/template><​style scoped>#components-pagination-demo-mini .ant-pagination:not(:last-child) {  margin-bottom: 24px;}<​/style>

-

  • /5

-

简洁

简单的翻页。

<​template>  <​a-pagination simple v-model:current="current" :total="50" /><​/template><​script lang="ts">import { defineComponent, ref } from 'vue';export default defineComponent({  setup() {    const current = ref<​number>(2);    return {      current,    };  },});<​/script>

总数

通过设置 showTotal 展示总共有多少数据。

<​template>  <​div>    <​a-pagination      :total="85"      :show-total="total => `Total ${total} items`"      :page-size="20"      v-model:current="current1"    />    <​br />    <​a-pagination      :total="85"      :show-total="(total, range) => `${range[0]}-${range[1]} of ${total} items`"      :page-size="20"      v-model:current="current2"    />  <​/div><​/template><​script lang="ts">import { defineComponent, ref } from 'vue';export default defineComponent({  setup() {    const current1 = ref<​number>(1);    const current2 = ref<​number>(2);    const onChange = (pageNumber: number) => {      console.log('Page: ', pageNumber);    };    return {      current1,      current2,      onChange,    };  },});<​/script>
  • Previous

  • 1

  • 2

  • 3

  • 4

  • 5

- •••

- 50

  • Next

上一步和下一步

修改上一步和下一步为文字链接。

<​template>  <​a-pagination :total="500">    <​template #itemRender="{ page, type, originalElement }">      <​a v-if="type === 'prev'">Previous<​/a>      <​a v-else-if="type === 'next'">Next<​/a>      <​renderVNode v-else :vnode="originalElement"><​/renderVNode>    <​/template>  <​/a-pagination><​/template><​script lang="ts">import { defineComponent, ref, watch } from 'vue';function renderVNode(_, { attrs: { vnode } }) {  return vnode;}export default defineComponent({  components: {    renderVNode,  },});<​/script>

API

<​a-pagination @change="onChange" :total="50" />
参数 说明 类型 默认值 版本
current(v-model) 当前页数 number -
pageSize(v-model) 每页条数 number -
defaultPageSize 默认的每页条数 number 10
disabled 禁用分页 boolean - 1.5.0
hideOnSinglePage 只有一页时是否隐藏分页器 boolean false

| itemRender | 用于自定义页码的结构,可用于优化 SEO | ({page, type: ‘page’ | ‘prev’ | ‘next’, originalElement}) => vNode | v-slot | - | | |---|---|---|---|---|

pageSizeOptions 指定每页可以显示多少条 string[] [‘10’, ‘20’, ‘30’, ‘40’]
showLessItems 是否显示较少页面内容 boolean false 1.5.0
showQuickJumper 是否可以快速跳转至某页 boolean false
showSizeChanger 是否可以改变 pageSize boolean false
showTotal 用于显示数据总量和当前数据顺序 Function(total, range) -
simple 当添加该属性时,显示为简单分页 boolean -
size 当为「small」时,是小尺寸分页 string “”
total 数据总数 number 0

事件

事件名称 说明 回调参数
change 页码改变的回调,参数是改变后的页码及每页条数 Function(page, pageSize)
showSizeChange pageSize 变化的回调 Function(current, size)