使用法
現在のページを制御するには、default-pageプロパティまたはv-model:pageディレクティブを使用します。
<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>Total
totalプロパティを使用して、リスト内のアイテムの合計数を設定します。
<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>ページごとのアイテム
items-per-pageプロパティを使用して、1ページあたりのアイテム数を設定します。デフォルトは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プロパティを使用して、表示する兄弟の数を設定します。デフォルトは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プロパティを使用して、省略記号、最初と最後のページを常に表示します。デフォルトはfalseです。
<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-controlsプロパティを使用して、最初、前、次、最後のボタンを表示します。デフォルトは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
colorプロパティを使用して、非アクティブなコントロールの色を設定します。デフォルトは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プロパティを使用して、非アクティブなコントロールのバリアントを設定します。デフォルトは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
active-colorプロパティを使用して、アクティブなコントロールの色を設定します。デフォルトは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バリアント
active-variantプロパティを使用して、アクティブコントロールのバリアントを設定します。デフォルトは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プロパティを使用してコントロールのサイズを設定します。デフォルトは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プロパティを使用して、ページネーションコントロールを無効にします。
<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>例
リンク付き
ボタンをリンクに変換するには、toプロパティを使用します。ページ番号を受け取り、ルート先を返す関数を渡します。
<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ハッシュを追加しています。API
Props
| 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; } |
スロット
| Slot | Type |
|---|---|
first | {} |
prev | {} |
next | {} |
last | {} |
ellipsis | { ui: object; } |
item | { page: number; pageCount: number; item: { type: "ellipsis"; } | { type: "page"; value: number; }; index: number; } |
Emits
| Event | Type |
|---|---|
update:page | [value: number] |
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: ''
}
}
}
})
]
})