Files
KF-OnlineJudge/frontend/src/composables/usePagination.ts
T
Kronecker 9fa25189a2 feat(frontend): establish shared components and blue page layouts
Add reusable headings, panels, tables, charts, pagination and explicit preview fixtures.
Apply the shared blue theme, responsive top navigation and Chinese UI locale.
2026-10-05 01:48:53 +08:00

14 lines
467 B
TypeScript

import { computed, ref, watch, type Ref } from 'vue'
export function usePagination<T>(items: Readonly<Ref<T[]>>, initialSize = 10) {
const page = ref(1)
const pageSize = ref(initialSize)
const total = computed(() => items.value.length)
const paged = computed(() =>
items.value.slice((page.value - 1) * pageSize.value, page.value * pageSize.value),
)
watch([items, pageSize], () => {
page.value = 1
})
return { page, pageSize, total, paged }
}