<el-table border :data="tableData[pageable.pageNum - 1]" style="width: 100%" height="250" ref="tableRef">
<el-table-column type="selection" width="55" />
<el-table-column type="index" label="序号" width="60" />
<el-table-column prop="id" label="id" />
<el-table-column prop="b" label="b" width="150" />
<el-table-column prop="c" label="c" />
<el-table-column label="操作" prop="operation" width="80">
<template #default="scope">
<el-button link type="primary" @click="deleteUser(scope.$index)">删除</el-button>
</template>
</el-table-column>
</el-table>
<el-pagination
v-model:current-page="currentPage"
v-model:page-size="pageSize"
:page-sizes="[10, 20, 50, 100]"
layout="total, sizes, prev, pager, next, jumper"
:total="total"
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
/>
const pageable = ref({
pageNum: 1,
pageSize: 25,
total: 0
});
const userList = ref<any>([]);
for (let i = 0; i < 1005; i++) {
if (i % 10 == 0) {
userList.value.push({ id: i + 1, b: "sb", c: "" });
} else {
userList.value.push({ id: i + 1, b: "sb", c: "13321618542" });
}
}
//总记录数等于数组的长度
total.value = userList.value.length;
const spliceArr = (list: any, length: any) => {
let arr = Object.assign([], list);
let index = 0;
let newArray = [];
while (index < arr.length) {
newArray.push(arr.splice(index, length));
}
return newArray;
};
//根据pageSize切割数组成n等分
let tableData = ref(spliceArr(userList.value, pageable.value.pageSize));
const handleSizeChange = (val: number) => {
pageable.value.pageSize = val;
tableData.value = spliceArr(userList.value, pageable.value.pageSize);
};
//切换当前页
const handleCurrentChange = (val: number) => {
pageable.value.pageNum = val;
};
vue3+ts+element 前端实现分页
小菜鸟码住2023-10-23 10:41
相关推荐
夏天想26 分钟前
前端安全和解决方案生椰拿铁You37 分钟前
11 —— 打包模式的应用Want59541 分钟前
HTML飞舞的爱心Hong.19481 小时前
vue本地调试设置虚拟域名童欧巴1 小时前
技术周刊 | 2024 前端趋势解读vvw&1 小时前
使用同一个链接,如何实现PC打开是web应用,手机打开是一个H5应用LKID体1 小时前
【python图解】数据结构之字典和集合命运之光2 小时前
【经典】抽奖系统(HTML,CSS、JS)IT-sec2 小时前
jquery-picture-cut 任意文件上传(CVE-2018-9208)subtle2 小时前
echarts+vue气泡图实践