For AI agents: the complete documentation index is available at https://docs.halo.run/llms.txt, the full documentation bundle is available at https://docs.halo.run/llms-full.txt, and this page is available as Markdown at https://docs.halo.run/developer-guide/plugin/api-reference/ui/base-components/pagination.md.

VPagination 分页

VPagination 用于列表底部的分页控制,支持页码切换、每页条数选择和总条数展示。

引入

import { VPagination } from "@halo-dev/components";

示例

基础用法

<script lang="ts" setup>
import { ref } from "vue";
import { VPagination } from "@halo-dev/components";

const page = ref(1);
const size = ref(10);
</script>

<template>
  <VPagination
    v-model:page="page"
    v-model:size="size"
    :total="126"
    :size-options="[10, 20, 50]"
  />
</template>

监听分页变化

<script lang="ts" setup>
import { ref } from "vue";
import { VPagination } from "@halo-dev/components";

const page = ref(1);
const size = ref(10);
const current = ref({ page: 1, size: 10 });

function handleChange(value: { page: number; size: number }) {
  current.value = value;
}
</script>

<template>
  <div class="space-y-3">
    <VPagination
      v-model:page="page"
      v-model:size="size"
      :total="86"
      :size-options="[10, 20, 50]"
      @change="handleChange"
    />
    <p class="text-sm text-gray-500">
      当前第 {{ current.page }} 页,每页 {{ current.size }} 条
    </p>
  </div>
</template>

自定义文案

<script lang="ts" setup>
import { ref } from "vue";
import { VPagination } from "@halo-dev/components";

const page = ref(1);
const size = ref(10);
</script>

<template>
  <VPagination
    v-model:page="page"
    v-model:size="size"
    :total="48"
    :size-options="[10, 20]"
    page-label="页"
    size-label="条 / 页"
    total-label="共 48 条评论"
  />
</template>

Props

属性类型默认值说明
pagenumber1当前页码,支持 v-model:page
sizenumber10每页条数,支持 v-model:size
totalnumber0数据总条数
sizeOptionsnumber[][10]每页条数选项
showTotalbooleantrue是否显示总条数
pageLabelstring"页"页码选择框后的文字
sizeLabelstring"条 / 页"每页条数选择框后的文字
totalLabelstringundefined自定义总条数文字,默认显示“共 N 项数据”

Emits

事件参数说明
update:pagenumber页码变化时触发
update:sizenumber每页条数变化时触发,页码会同时重置为 1
change{ page: number; size: number }页码或每页条数变化时触发