Use a prop default-page ou a diretiva v-model:page para controlar a página atual.
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<NPagination v-model:page="page" :total="100" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const page = ref(5)
</script>
<template>
<NPagination v-model:page="page" :total="100" />
</template>
Button para exibir as páginas; use as props color, variant e size para estilizá-los.Use a prop total para definir o número total de itens na lista.
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<NPagination v-model:page="page" :total="100" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const page = ref(5)
</script>
<template>
<NPagination v-model:page="page" :total="100" />
</template>
Use a prop items-per-page para definir o número de itens por página. O padrão é 10.
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<NPagination 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>
<NPagination v-model:page="page" :items-per-page="20" :total="100" />
</template>
Use a prop sibling-count para definir o número de irmãos a exibir. O padrão é 2.
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<NPagination v-model:page="page" :sibling-count="1" :total="100" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const page = ref(5)
</script>
<template>
<NPagination v-model:page="page" :sibling-count="1" :total="100" />
</template>
Use a prop show-edges para sempre exibir as reticências e as primeiras e últimas páginas. O padrão é false.
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<NPagination 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>
<NPagination v-model:page="page" show-edges :sibling-count="1" :total="100" />
</template>
Use a prop show-controls para exibir os botões de primeira, anterior, próxima e última. O padrão é true.
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<NPagination 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>
<NPagination v-model:page="page" :show-controls="false" show-edges :total="100" />
</template>
Use a prop color para definir a cor dos controles inativos. O padrão é neutral.
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<NPagination v-model:page="page" color="primary" :total="100" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const page = ref(5)
</script>
<template>
<NPagination v-model:page="page" color="primary" :total="100" />
</template>
Use a prop variant para definir a variante dos controles inativos. O padrão é outline.
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<NPagination 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>
<NPagination v-model:page="page" color="neutral" variant="subtle" :total="100" />
</template>
Use a prop active-color para definir a cor do controle ativo. O padrão é primary.
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<NPagination v-model:page="page" active-color="neutral" :total="100" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const page = ref(5)
</script>
<template>
<NPagination v-model:page="page" active-color="neutral" :total="100" />
</template>
Use a prop active-variant para definir a variante do controle ativo. O padrão é solid.
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<NPagination 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>
<NPagination v-model:page="page" active-color="primary" active-variant="subtle" :total="100" />
</template>
Use a prop size para definir o tamanho dos controles. O padrão é md.
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<NPagination v-model:page="page" size="xl" :total="100" />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const page = ref(5)
</script>
<template>
<NPagination v-model:page="page" size="xl" :total="100" />
</template>
Use a prop disabled para desabilitar os controles de paginação.
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<NPagination v-model:page="page" :total="100" disabled />
</template>
<script setup lang="ts">
import { ref } from 'vue'
const page = ref(5)
</script>
<template>
<NPagination v-model:page="page" :total="100" disabled />
</template>
Use a prop to para transformar os botões em links. Passe uma função que recebe o número da página e retorna um destino de rota.
#with-links para evitar ir ao topo da página.| 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" | "accent" | "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" | "accent" | "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; } |
| Slot | Type |
|---|---|
first | {} |
prev | {} |
next | {} |
last | {} |
ellipsis | { ui: object; } |
item | { page: number; pageCount: number; item: { type: "ellipsis"; } | { type: "page"; value: number; }; index: number; } |
| Event | Type |
|---|---|
update:page | [value: number] |
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 '@nitro/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: ''
}
}
}
})
]
})