Pagination
Pagination (페이지네이션)
Pagination 컴포넌트는 페이지 사이를 탐색하기 위한 버튼 또는 링크 목록이에요. v-model:page를 사용해 현재 페이지를 제어하고 total로 전체 항목 수를 설정해요.
출처: Nuxt UI
본문
사용법 (Usage)
default-page prop 또는 v-model:page 지시자를 사용해 현재 페이지를 제어하세요.
<script setup lang="ts">
const page = ref(5)
</script>
<template>
<UPagination v-model:page="page" :total="100" />
</template>
[!NOTE]
Pagination 컴포넌트는 페이지를 표시하기 위해 일부
Button을 사용해요. 스타일을 지정하려면color,variant,sizeprop을 사용하세요.
전체 수 (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으로 표시할 형제(sibling) 개수를 설정하세요. 기본값은 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>
예제 (Examples)
링크 사용 (With links)
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>
[!NOTE]
이 예제에서는 페이지 상단으로 이동하지 않도록
#with-links해시를 추가하고 있어요.
API
Props (속성)
/**
* Props for the Pagination component
*/
interface PaginationProps {
/**
* The element or component this component should render as.
* @default 'div'
*/
as?: any;
/**
* The icon to use for the first page control.
* @default appConfig.ui.icons.chevronDoubleLeft
*/
firstIcon?: any;
/**
* The icon to use for the previous page control.
* @default appConfig.ui.icons.chevronLeft
*/
prevIcon?: any;
/**
* The icon to use for the next page control.
* @default appConfig.ui.icons.chevronRight
*/
nextIcon?: any;
/**
* The icon to use for the last page control.
* @default appConfig.ui.icons.chevronDoubleRight
*/
lastIcon?: any;
/**
* The icon to use for the ellipsis control.
* @default appConfig.ui.icons.ellipsis
*/
ellipsisIcon?: any;
/**
* The color of the pagination controls.
* @default 'neutral'
*/
color?: "error" | "neutral" | "primary" | "secondary" | "success" | "info" | "warning" | undefined;
/**
* The variant of the pagination controls.
* @default 'outline'
*/
variant?: "outline" | "solid" | "soft" | "subtle" | "ghost" | "link" | undefined;
/**
* The color of the active pagination control.
* @default 'primary'
*/
activeColor?: "error" | "neutral" | "primary" | "secondary" | "success" | "info" | "warning" | undefined;
/**
* The variant of the active pagination control.
* @default 'solid'
*/
activeVariant?: "outline" | "solid" | "soft" | "subtle" | "ghost" | "link" | undefined;
/**
* Whether to show the first, previous, next, and last controls.
* @default true
*/
showControls?: boolean | undefined;
size?: "xs" | "sm" | "md" | "lg" | "xl" | undefined;
/**
* A function to render page controls as links.
*/
to?: (page: number): string | RouteLocationAsRelativeGeneric | RouteLocationAsPathGeneric | undefined | undefined;
ui?: { root?: SlotClass; list?: SlotClass; ellipsis?: SlotClass; label?: SlotClass; first?: SlotClass; prev?: SlotClass; item?: SlotClass; next?: SlotClass; last?: SlotClass; } | undefined;
/**
* The value of the page that should be active when initially rendered.
*
* Use when you do not need to control the value state.
*/
defaultPage?: number | undefined;
/**
* When `true`, prevents the user from interacting with item
*/
disabled?: boolean | undefined;
/**
* Number of items per page
* @default 10
*/
itemsPerPage?: number | undefined;
/**
* The controlled value of the current page. Can be binded as `v-model:page`.
*/
page?: number | undefined;
/**
* When `true`, always show first page, last page, and ellipsis
* @default false
*/
showEdges?: boolean | undefined;
/**
* Number of sibling should be shown around the current page
* @default 2
*/
siblingCount?: number | undefined;
/**
* Number of items in your list
* @default 0
*/
total?: number | undefined;
}
Slots (슬롯)
/**
* Slots for the Pagination component
*/
interface PaginationSlots {
first(): any;
prev(): any;
next(): any;
last(): any;
ellipsis(): any;
item(): any;
}
Emits (이벤트)
/**
* Emitted events for the Pagination component
*/
interface PaginationEmits {
update:page: (payload: [value: number]) => void;
}
테마 (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: ''
}
}
}
})