安裝
Terminal
pnpm dlx shadcn-vue add @admin/paginationimport { AdminPagination, AdminPaginationContent, AdminPaginationEllipsis, AdminPaginationFirst, AdminPaginationInfo, AdminPaginationItem, AdminPaginationLast, AdminPaginationNext, AdminPaginationPerPage, AdminPaginationPrevious,} from '@/components/admin/pagination'用法
<script setup lang="ts">import { ref } from 'vue'import { AdminPagination, AdminPaginationContent, AdminPaginationEllipsis, AdminPaginationItem, AdminPaginationNext, AdminPaginationPrevious} from '@/components/admin/pagination'const page = ref(1)</script><template> <admin-pagination v-model:page="page" :items-per-page="10" :show-edges="true" :sibling-count="1" :total="100" > <admin-pagination-content v-slot="{ items }"> <admin-pagination-previous /> <template v-for="(item, idx) in items" :key="idx"> <admin-pagination-item v-if="item.type === 'page'" :value="item.value">{{ item.value }}</admin-pagination-item> <admin-pagination-ellipsis v-else /> </template> <admin-pagination-next /> </admin-pagination-content> </admin-pagination></template>場景
完整樣式(含資訊 + 每頁筆數)
<script setup lang="ts">import { ref, watch } from 'vue'import { AdminPagination, AdminPaginationContent, AdminPaginationEllipsis, AdminPaginationFirst, AdminPaginationInfo, AdminPaginationItem, AdminPaginationLast, AdminPaginationNext, AdminPaginationPerPage, AdminPaginationPrevious} from '@/components/admin/pagination'const page = ref(3)const itemsPerPage = ref(10)watch(itemsPerPage, () => { page.value = 1})</script><template> <admin-pagination v-model:items-per-page="itemsPerPage" v-model:page="page" :total="235"> <admin-pagination-info :total="235" /> <admin-pagination-content v-slot="{ items }"> <admin-pagination-first /> <admin-pagination-previous /> <template v-for="(item, index) in items" :key="index"> <admin-pagination-item v-if="item.type === 'page'" :value="item.value"> {{ item.value }} </admin-pagination-item> <admin-pagination-ellipsis v-else :index="index" /> </template> <admin-pagination-next /> <admin-pagination-last /> </admin-pagination-content> <admin-pagination-per-page v-model="itemsPerPage" :options="[10, 20, 50, 100]" /> </admin-pagination></template>API 參考
組成
<template> <admin-pagination v-model:page="page" :items-per-page="perPage" :total="total"> <admin-pagination-content> <admin-pagination-first /> <admin-pagination-previous /> <admin-pagination-item :value="1" /> <admin-pagination-ellipsis /> <admin-pagination-next /> <admin-pagination-last /> </admin-pagination-content> <admin-pagination-info /> <admin-pagination-per-page v-model="perPage" /> </admin-pagination></template>admin-pagination
Props
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
page | number | undefined | — | The controlled value of the current page. Can be binded as `v-model:page`. |
defaultPage | number | undefined | — | The value of the page that should be active when initially rendered. Use when you do not need to control the value state. |
itemsPerPage* | number | — | Number of items per page |
total | number | undefined | — | Number of items in your list |
siblingCount | number | undefined | — | Number of sibling should be shown around the current page |
disabled | boolean | undefined | — | When `true`, prevents the user from interacting with item |
showEdges | boolean | undefined | — | When `true`, always show first page, last page, and ellipsis |
asChild | boolean | undefined | — | Change the default rendered element for the one passed as a child, merging their props and behavior. Read our [Composition](https://www.reka-ui.com/docs/guides/composition) guide for more details. |
as | globalThis.Component | AsTag | undefined | "div" | The element or component this component should render as. Can be overwritten by `asChild`. |
class | ClassValue | — | 根元素之自訂 class |
* 代表必填
Events
| 名稱 | Payload | 說明 |
|---|---|---|
update:page | number | — |
Slots
| 名稱 | Bindings | 說明 |
|---|---|---|
default | { page: number; pageCount: number; } | — |
admin-pagination-item
Props
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
value* | number | — | Value for the page |
asChild | boolean | undefined | — | Change the default rendered element for the one passed as a child, merging their props and behavior. Read our [Composition](https://www.reka-ui.com/docs/guides/composition) guide for more details. |
as | globalThis.Component | AsTag | undefined | "div" | The element or component this component should render as. Can be overwritten by `asChild`. |
class | ClassValue | — | 根元素之自訂 class |
* 代表必填
Slots
| 名稱 | Bindings | 說明 |
|---|---|---|
default | {} | — |
admin-pagination-info
Props
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
total | number | undefined | — | 顯示總筆數 |
class | ClassValue | — | 根元素之自訂 class |
Slots
| 名稱 | Bindings | 說明 |
|---|---|---|
default | { pageCount: number; total?: number | undefined; } | — |
admin-pagination-per-page
Props
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
options | number[] | undefined | [10, 20, 50, 100] | 每頁筆數選項 |
labelFormat | ((value: number) => string) | undefined | — | 自訂選項 label 格式化函式 |
class | ClassValue | — | 根元素之自訂 class |
modelValue* | number | — | — |
* 代表必填
Events
| 名稱 | Payload | 說明 |
|---|---|---|
update:modelValue | number | — |
admin-pagination-content
Props
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
asChild | boolean | undefined | — | Change the default rendered element for the one passed as a child, merging their props and behavior. Read our [Composition](https://www.reka-ui.com/docs/guides/composition) guide for more details. |
as | globalThis.Component | AsTag | undefined | "div" | The element or component this component should render as. Can be overwritten by `asChild`. |
class | ClassValue | — | 根元素之自訂 class |
Slots
| 名稱 | Bindings | 說明 |
|---|---|---|
default | { items: ({ type: "ellipsis"; } | { type: "page"; value: number; })[]; } | — |
admin-pagination-ellipsis
Props
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
asChild | boolean | undefined | — | Change the default rendered element for the one passed as a child, merging their props and behavior. Read our [Composition](https://www.reka-ui.com/docs/guides/composition) guide for more details. |
as | globalThis.Component | AsTag | undefined | "div" | The element or component this component should render as. Can be overwritten by `asChild`. |
class | ClassValue | — | 根元素之自訂 class |
Slots
| 名稱 | Bindings | 說明 |
|---|---|---|
default | {} | — |
admin-pagination-first
Props
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
asChild | boolean | undefined | — | Change the default rendered element for the one passed as a child, merging their props and behavior. Read our [Composition](https://www.reka-ui.com/docs/guides/composition) guide for more details. |
as | globalThis.Component | AsTag | undefined | "div" | The element or component this component should render as. Can be overwritten by `asChild`. |
class | ClassValue | — | 根元素之自訂 class |
Slots
| 名稱 | Bindings | 說明 |
|---|---|---|
default | {} | — |
admin-pagination-last
Props
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
asChild | boolean | undefined | — | Change the default rendered element for the one passed as a child, merging their props and behavior. Read our [Composition](https://www.reka-ui.com/docs/guides/composition) guide for more details. |
as | globalThis.Component | AsTag | undefined | "div" | The element or component this component should render as. Can be overwritten by `asChild`. |
class | ClassValue | — | 根元素之自訂 class |
Slots
| 名稱 | Bindings | 說明 |
|---|---|---|
default | {} | — |
admin-pagination-next
Props
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
asChild | boolean | undefined | — | Change the default rendered element for the one passed as a child, merging their props and behavior. Read our [Composition](https://www.reka-ui.com/docs/guides/composition) guide for more details. |
as | globalThis.Component | AsTag | undefined | "div" | The element or component this component should render as. Can be overwritten by `asChild`. |
class | ClassValue | — | 根元素之自訂 class |
Slots
| 名稱 | Bindings | 說明 |
|---|---|---|
default | {} | — |
admin-pagination-previous
Props
| 名稱 | 型別 | 預設值 | 說明 |
|---|---|---|---|
asChild | boolean | undefined | — | Change the default rendered element for the one passed as a child, merging their props and behavior. Read our [Composition](https://www.reka-ui.com/docs/guides/composition) guide for more details. |
as | globalThis.Component | AsTag | undefined | "div" | The element or component this component should render as. Can be overwritten by `asChild`. |
class | ClassValue | — | 根元素之自訂 class |
Slots
| 名稱 | Bindings | 說明 |
|---|---|---|
default | {} | — |