tav-ui
Version:
28 lines (25 loc) • 890 B
JavaScript
import { ref, computed, unref } from 'vue';
function pagination(list, pageNo, pageSize) {
const offset = (pageNo - 1) * Number(pageSize);
const ret = offset + Number(pageSize) >= list.length ? list.slice(offset, list.length) : list.slice(offset, offset + Number(pageSize));
return ret;
}
function usePagination(list, pageSize) {
const currentPage = ref(1);
const pageSizeRef = ref(pageSize);
const getPaginationList = computed(() => {
return pagination(unref(list), unref(currentPage), unref(pageSizeRef));
});
const getTotal = computed(() => {
return unref(list).length;
});
function setCurrentPage(page) {
currentPage.value = page;
}
function setPageSize(pageSize2) {
pageSizeRef.value = pageSize2;
}
return { setCurrentPage, getTotal, setPageSize, getPaginationList };
}
export { usePagination };
//# sourceMappingURL=usePagination2.mjs.map