<template>
<el-pagination
:current-page="currentPage"
:page-sizes="pageSizes"
:page-size="pageSize"
:total="total"
layout="total, sizes, prev, pager, next, jumper"
@size-change="handleSizeChange"
@current-change="handleCurrentChange">
</el-pagination>
</template>
<script>
export default {
data() {
return {
currentPage: 1,
pageSize: 10,
total: 1000,
pageSizes: [10, 20, 30, 40, 50]
};
},
created() {
this.calculatePageSizes();
},
methods: {
calculatePageSizes() {
// 假设每条数据高度约为40px,并且你想要留出一定的边距和其他布局元素的空间
const approxItemHeight = 40;
// 留出布局
const marginAndPadding = 200;
// 计算可以显示多少条数据
const pageSize = Math.floor((window.innerHeight - marginAndPadding) / approxItemHeight);
// 根据计算结果更新 pageSizes
this.pageSizes = [10, 20, 50, 100].filter(size => size <= pageSize).sort((a, b) => a - b);
},
handleSizeChange(val) {
this.pageSize = val;
},
handleCurrentChange(val) {
this.currentPage = val;
}
}
};
</script>
el-pagination根据页面高度自动计算page-sizes
最新推荐文章于 2024-07-19 10:30:06 发布