Pagination
Bearbeiten
Verwenden Sie die default-page prop oder die v-model:page Direktive, um die aktuelle Seite zu steuern.
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" :total="100" />
</template><script setup lang="ts">
import { ref } from 'vue'
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" :total="100" />
</template>Button, um die Seiten anzuzeigen, verwenden Sie color, variant und [size](](), um sie zu stylen.Total Bearbeiten
Verwenden Sie die total-prop, um die Gesamtzahl der Elemente in der Liste festzulegen.
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" :total="100" />
</template><script setup lang="ts">
import { ref } from 'vue'
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" :total="100" />
</template>Elemente pro Seite
Verwenden Sie die items-per-page-prop, um die Anzahl der Elemente pro Seite festzulegen. Standardmäßig ist 10.
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" :items-per-page="20" :total="100" />
</template><script setup lang="ts">
import { ref } from 'vue'
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" :items-per-page="20" :total="100" />
</template>Sibling Count (englisch)
Verwenden Sie die sibling-count-prop, um die Anzahl der Geschwister zu zeigen. Standardmäßig auf 2.
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" :sibling-count="1" :total="100" />
</template><script setup lang="ts">
import { ref } from 'vue'
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" :sibling-count="1" :total="100" />
</template>Show Kanten
Verwenden Sie die show-edges-prop, um immer die Auslassungspunkte, die erste und die letzte Seite anzuzeigen.
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" show-edges :sibling-count="1" :total="100" />
</template><script setup lang="ts">
import { ref } from 'vue'
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" show-edges :sibling-count="1" :total="100" />
</template>Show Steuerung
Verwenden Sie die show-controls-prop, um die ersten, prev, next und last Tasten anzuzeigen. Standardmäßig ist true.
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" :show-controls="false" show-edges :total="100" />
</template><script setup lang="ts">
import { ref } from 'vue'
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" :show-controls="false" show-edges :total="100" />
</template>Color (englisch)
Verwenden Sie die color-prop, um die Farbe der inaktiven Steuerelemente einzustellen. Standardmäßig ist neutral.
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" color="primary" :total="100" />
</template><script setup lang="ts">
import { ref } from 'vue'
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" color="primary" :total="100" />
</template>Variant Bearbeiten
Verwenden Sie die variant-prop, um die Variante der inaktiven Steuerelemente festzulegen. Standardmäßig outline.
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" color="neutral" variant="subtle" :total="100" />
</template><script setup lang="ts">
import { ref } from 'vue'
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" color="neutral" variant="subtle" :total="100" />
</template>Active Color (englisch)
Verwenden Sie die active-color-Prop, um die Farbe des aktiven Steuerelements einzustellen. Standardmäßig ist primary.
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" active-color="neutral" :total="100" />
</template><script setup lang="ts">
import { ref } from 'vue'
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" active-color="neutral" :total="100" />
</template>Active Variante Bearbeiten
Verwenden Sie die active-variant-prop, um die Variante der aktiven Steuerung einzustellen. Standardmäßig ist 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><script setup lang="ts">
import { ref } from 'vue'
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" active-color="primary" active-variant="subtle" :total="100" />
</template>Size
Verwenden Sie die size-prop, um die Größe der Steuerelemente einzustellen. Standardmäßig ist md.
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" size="xl" :total="100" />
</template><script setup lang="ts">
import { ref } from 'vue'
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" size="xl" :total="100" />
</template>Disabled (englisch)
Verwenden Sie die disabled-Prop, um die Paginierungskontrollen zu deaktivieren.
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" :total="100" disabled />
</template><script setup lang="ts">
import { ref } from 'vue'
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" :total="100" disabled />
</template>Examples Bearbeiten
mit Links
Verwenden Sie die prop to, um Schaltflächen in Links zu verwandeln. Übergeben Sie eine Funktion, die die Seitenzahl empfängt und ein Routenziel zurückgibt.
<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>
<script setup lang="ts">
import { ref } from 'vue'
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 hinzu, um zu vermeiden, dass der Anfang der Seite angezeigt wird.API ist
Props Bearbeiten
| Prop | Default | Type |
|---|---|---|
as | 'div' | anyThe element or component this component should render as. |
firstIcon | appConfig.ui.icons.chevronDoubleLeft | anyThe icon to use for the first page control. |
prevIcon | appConfig.ui.icons.chevronLeft | anyThe icon to use for the previous page control. |
nextIcon | appConfig.ui.icons.chevronRight | anyThe icon to use for the next page control. |
lastIcon | appConfig.ui.icons.chevronDoubleRight | anyThe icon to use for the last page control. |
ellipsisIcon | appConfig.ui.icons.ellipsis | anyThe icon to use for the ellipsis control. |
color | 'neutral' | "error" | "neutral" | "primary" | "secondary" | "success" | "info" | "warning"The color of the pagination controls. |
variant | 'outline' | "outline" | "solid" | "soft" | "subtle" | "ghost" | "link"The variant of the pagination controls. |
activeColor | 'primary' | "error" | "neutral" | "primary" | "secondary" | "success" | "info" | "warning"The color of the active pagination control. |
activeVariant | 'solid' | "outline" | "solid" | "soft" | "subtle" | "ghost" | "link"The variant of the active pagination control. |
showControls | true | boolean Whether to show the first, previous, next, and last controls. |
size | "xs" | "sm" | "md" | "lg" | "xl" | |
to | (page: number): string | RouteLocationAsRelativeGeneric | RouteLocationAsPathGeneric A function to render page controls as links. | |
defaultPage | numberThe value of the page that should be active when initially rendered. Use when you do not need to control the value state. | |
disabled | boolean When | |
itemsPerPage | 10 | numberNumber of items per page |
page | numberThe controlled value of the current page. Can be binded as | |
showEdges | false | boolean When |
siblingCount | 2 | numberNumber of sibling should be shown around the current page |
total | 0 | numberNumber of items in your list |
ui | { root?: SlotClass; list?: SlotClass; ellipsis?: SlotClass; label?: SlotClass; first?: SlotClass; prev?: SlotClass; item?: SlotClass; next?: SlotClass; last?: SlotClass; } |
Slots Bearbeiten
| Slot | Type |
|---|---|
first | {} |
prev | {} |
next | {} |
last | {} |
ellipsis | { ui: object; } |
item | { page: number; pageCount: number; item: { type: "ellipsis"; } | { type: "page"; value: number; }; index: number; } |
Emits (englisch)
| Event | Type |
|---|---|
update:page | [value: number] |
Theme Bearbeiten
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: ''
}
}
}
})
]
})