当前位置:   article > 正文

vue+elementUI组件table实现前端分页功能_el-table 显示上一页下一页

el-table 显示上一页下一页

 前端分页和后端分页就是请求的差异,前端分页的话只请求一次,所以要在render table组件的时候控制下数据

:data="tableData.slice((currentPage-1)*pageSize,currentPage*pageSize)

然后total等于table数据的长度

:total="tableData.length"

具体代码如下:

  1. <el-dialog title="报修设备列表" :visible.sync="dialogRepairDevicesTable" width="60%">
  2. <el-table
  3. :data="repairOrder.repairDevices.slice((currentPage-1)*pageSize,currentPage*pageSize)"
  4. >
  5. <el-table-column property="deviceNumber" label="编号" />
  6. <el-table-column property="deviceName" label="名称" />
  7. <el-table-column property="category" label="类别" sortable />
  8. <el-table-column property="area.areaName" label="区域" />
  9. <el-table-column property="spot.spotName" label="点位" />
  10. <!-- <el-table-column property="competentUnit" label="主管单位" /> -->
  11. <!-- <el-table-column property="maintainProject" label="维护项目" /> -->
  12. <el-table-column property="warrantyDuration" label="质保时长" />
  13. <el-table-column property="maintainUnit" label="维护单位" />
  14. <el-table-column property="maintainState" label="维保状态" />
  15. <el-table-column property="deviceState" label="设备状态" />
  16. <el-table-column
  17. align="right"
  18. >
  19. <template slot-scope="scope">
  20. <el-button
  21. size="mini"
  22. type="danger"
  23. @click="repairDevicesDelete(scope.$index, scope.row)"
  24. >删除</el-button>
  25. </template>
  26. </el-table-column>
  27. </el-table>
  28. <el-pagination
  29. :current-page.sync="currentPage"
  30. :page-size="pageSize"
  31. :page-sizes="[5, 10, 15, 20]"
  32. layout="total, sizes, prev, pager, next, jumper, slot"
  33. :total="repairOrder.repairDevices.length"
  34. prev-text="上一页"
  35. next-text="下一页"
  36. align="center"
  37. @size-change="handleSizeChange"
  38. @current-change="handleCurrentChange"
  39. />
  40. <div slot="footer">
  41. <el-button @click="dialogRepairDevicesTable = false">取 消</el-button>
  42. </div>
  43. </el-dialog>
  1. data(){
  2. return{
  3. repairOrder: {
  4. organizer: '',
  5. initiationMethod: '',
  6. faultTypes: [],
  7. faultDescription: '',
  8. repairDevices: [],
  9. faultTime: null,
  10. faultImgs: [],
  11. priority: ''
  12. },
  13. dialogRepairDevicesTable: false,
  14. currentPage: 1,
  15. pageSize: 5
  16. }
  17. }
  1. repairDevicesDelete(index, row) {
  2. this.repairOrder.repairDevices.map((e, i) => {
  3. if (e.uuid === row.uuid) {
  4. this.repairOrder.repairDevices.splice(i, 1)
  5. }
  6. })
  7. },
  8. handleCurrentChange(val) {
  9. console.log(`当前页: ${val}`);
  10. this.pageNumRepairDevices = val
  11. },
  12. handleSizeChange(val) {
  13. console.log(`每页 ${val} 条`);
  14. this.pageNumRepairDevices = 1
  15. this.pageSizeRepairDevices = val
  16. },

声明:本文内容由网友自发贡献,转载请注明出处:【wpsshop】
推荐阅读
相关标签
  

闽ICP备14008679号