在vue项目中利用json数据来模拟进行分页
<!-- 表格 -->
<el-table :data="tableData.slice((currentPage-1)*pageSize,currentPage*pageSize)" stripe border >
<el-table-column prop="date" label="日期" width="140">
</el-table-column>
<el-table-column prop="name" label="姓名" width="120">
</el-table-column>
<el-table-column prop="address" label="地址">
</el-table-column>
<el-table-column fixed="right" label="操作" width="200px">
<template>
<el-button type="primary" icon="el-icon-search" size="small">查看</el-button>
<el-button type="primary" icon="el-icon-edit" size="small">编辑</el-button>
</template>
</el-table-column>
</el-table>
<!-- 分页 -->
<el-pagination
@size-change="handleSizeChange"
@current-change="handleCurrentChange"
:current-page="currentPage"
:page-sizes="[2, 5, 8, 10]"
:page-size="pageSize"
layout="total, sizes, prev, pager, next, jumper"
:total="tableData.length"
align="center"
>
接着是数据跟方法:
tableData:[
{
date:"",
name:"",
address:"",
}
],
dialogVisible:false,
total:tableData.length,
currentPage: 1,
pageSize: 2
// 获取表格数据
getUserList(){
this.tableData = tableData;
console.log(tableData);
},
// 分页
handleSizeChange(val) {
this.pageSize = val;
console.log(`每页 ${val} 条`);
},
handleCurrentChange(val) {
this.currentPage = val;
console.log(`当前页: ${val}`);
}
}