Pagination
xph0000xUso
Utilice la directiva default-page o la directiva v-model:page para controlar la página actual.
<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 para mostrar las páginas, usa los accesorios color, [variantxph028#variant) y [size](xph0333xph0x para darles estilo.Total (Edición española)
Utilice el prop total para establecer el número total de elementos en la lista.
<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>Artículos por página
Utilice el prop items-per-page para establecer el número de elementos por página.
<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>Conteo de hermanos
Utilice el prop sibling-count para establecer el número de hermanos a mostrar. Predeterminados a 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 Edges (Edición española)
Utilice el prop show-edges para mostrar siempre los puntos suspensivos, la primera y la última página.
<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 Controles
Utilice el prop show-controls para mostrar los botones primero, anterior, siguiente y último.
<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>Xph111xColor (Edición española)
Utilice el prop color para establecer el color de los controles inactivos.
<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>Variante
Utilice el prop variant para establecer la variante de los controles inactivos. Predeterminados a 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>XPH169xColor activo
Utilice el prop active-color para establecer el color del control activo.
<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 Versión
Utilice el prop active-variant para establecer la variante del control activo. Predeterminados a 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>Tamaño
Utilice el prop size para establecer el tamaño de los controles. Predeterminados a 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
Utilice el prop disabled para desactivar los controles de paginación.
<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>Ejemplos
Con enlaces
Utilice el prop to para transformar los botones en enlaces. Pase una función que recibe el número de página y devuelve un destino de ruta.
<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 para evitar ir a la parte superior de la página.API
Props (accesorios)
| 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 en línea
| Slot | Type |
|---|---|
first | {} |
prev | {} |
next | {} |
last | {} |
ellipsis | { ui: object; } |
item | { page: number; pageCount: number; item: { type: "ellipsis"; } | { type: "page"; value: number; }; index: number; } |
Emisiones
| Event | Type |
|---|---|
update:page | [value: number] |
Temas
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: ''
}
}
}
})
]
})