Pagination
用法
使用 default-page prop 或 v-model:page 指令控制当前页面。
总数 (Total)
使用 total prop 设置列表中项目的总数。
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" :total="100" />
</template>
每页项目数 (Items Per Page)
使用 items-per-page prop 设置每页显示的项目数。默认为 10。
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" :items-per-page="20" :total="100" />
</template>
兄弟数量 (Sibling Count)
使用 sibling-count prop 设置要显示的兄弟页码数量。默认为 2。
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" :sibling-count="1" :total="100" />
</template>
显示边缘 (Show Edges)
使用 show-edges prop 始终显示省略号、第一页和最后一页。默认为 false。
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" show-edges :sibling-count="1" :total="100" />
</template>
显示控制 (Show Controls)
使用 show-controls prop 显示第一页、上一页、下一页和最后一页按钮。默认为 true。
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" :show-controls="false" show-edges :total="100" />
</template>
颜色 (Color)
使用 color prop 设置非活动控件的颜色。默认为 neutral。
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" color="primary" :total="100" />
</template>
变体 (Variant)
使用 variant prop 设置非活动控件的变体。默认为 outline。
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" color="neutral" variant="subtle" :total="100" />
</template>
活动颜色 (Active Color)
使用 active-color prop 设置活动控件的颜色。默认为 primary。
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" active-color="neutral" :total="100" />
</template>
活动变体 (Active Variant)
使用 active-variant prop 设置活动控件的变体。默认为 solid。
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" active-color="primary" active-variant="subtle" :total="100" />
</template>
尺寸 (Size)
使用 size prop 设置控件的尺寸。默认为 md。
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" size="xl" :total="100" />
</template>
禁用 (Disabled)
使用 disabled prop 禁用分页控件。
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" :total="100" disabled />
</template>
示例
带链接
使用 to prop 将按钮转换为链接。传入一个接收页码并返回路由目标的函数。
<script setup lang="ts">
const page = ref(5)
function to(page: number) {
return {
query: {
page
},
hash: '#with-links'
}
}
</script>
<template>
<UPagination v-model:page="page" :total="100" :to="to" :sibling-count="1" show-edges />
</template>
#with-links hash 以避免跳转到页面顶部。API
Props
| Prop | Default | Type |
|---|---|---|
as |
|
The element or component this component should render as. |
firstIcon |
|
The icon to use for the first page control. |
prevIcon |
|
The icon to use for the previous page control. |
nextIcon |
|
The icon to use for the next page control. |
lastIcon |
|
The icon to use for the last page control. |
ellipsisIcon |
|
The icon to use for the ellipsis control. |
color |
|
The color of the pagination controls. |
variant |
|
The variant of the pagination controls. |
activeColor |
|
The color of the active pagination control. |
activeVariant |
|
The variant of the active pagination control. |
showControls |
|
Whether to show the first, previous, next, and last controls. |
size |
| |
to |
A function to render page controls as links. | |
disabled |
When | |
page |
The controlled value of the current page. Can be binded as | |
defaultPage |
The value of the page that should be active when initially rendered. Use when you do not need to control the value state. | |
itemsPerPage |
|
Number of items per page |
showEdges |
|
When |
siblingCount |
|
Number of sibling should be shown around the current page |
total |
|
Number of items in your list |
ui |
|
Slots
| Slot | Type |
|---|---|
first |
|
prev |
|
next |
|
last |
|
ellipsis |
|
item |
|
Emits
| Event | Type |
|---|---|
update:page |
|
Theme
export default defineAppConfig({
ui: {
pagination: {
slots: {
root: '',
list: 'flex items-center gap-1',
ellipsis: 'pointer-events-none',
label: 'min-w-5 text-center',
first: '',
prev: '',
item: '',
next: '',
last: ''
}
}
}
})
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import ui from '@nuxt/ui/vite'
export default defineConfig({
plugins: [
vue(),
ui({
ui: {
pagination: {
slots: {
root: '',
list: 'flex items-center gap-1',
ellipsis: 'pointer-events-none',
label: 'min-w-5 text-center',
first: '',
prev: '',
item: '',
next: '',
last: ''
}
}
}
})
]
})
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import uiPro from '@nuxt/ui-pro/vite'
export default defineConfig({
plugins: [
vue(),
uiPro({
ui: {
pagination: {
slots: {
root: '',
list: 'flex items-center gap-1',
ellipsis: 'pointer-events-none',
label: 'min-w-5 text-center',
first: '',
prev: '',
item: '',
next: '',
last: ''
}
}
}
})
]
})