The backend returns a large amount of data at a time, and the frontend does paging processing

Description of the problem: The backend interface returns a large amount of data, without paging processing, and does not support parameter passing pageNum, pageSize

This article is a reprinted article, the original article: the backend returns a large amount of data at a time, and the frontend does paging processing

1. In the template

paging

<el-pagination
  @size-change="handleSizeChange"
  :page-sizes="[10, 20, 50, 100]"
  style="float:right"
  @current-change="currentChangeHandle"
  :current-page="currentPage"
  :page-size="pageSize"
  :total="totalPage"
  layout="total, sizes,prev, pager, next, jumper">
</el-pagination>

corresponding model

 data(){
    
    
   return{
    
    
     totalPage:0,      // 数据总条数
     currentPage:1,   // 当前页面
     pageSize:10,     // 当前页面显示条数
     dataList: [],		// 页面展示数据
     tableData: []		// 后端获取的总数据
   }
 },

insert image description here
2. script

Get backend data

//获取初始数据
getDataList(){
    
    
  api.agentDealiyWMExport(this.dataForm).then(res=>{
    
    
    if(res.data.HEAD.CODE=='000'){
    
    
      this.totalPage=res.data.BODY.total;
      // 获取后端返回所有数据
      this.tableData=res.data.BODY.rows; 
      // 对所有数据进行处理,截取数据前 n条数据,显示到页面上
      this.dataList=this.tableData.slice(0, this.pageSize)
    }
  })
},

change page event

// val 是当前页数
currentChangeHandle (val) {
    
    
  this.currentPage=val;
  this.dataList = this.tableData.slice((val - 1) * this.pageSize, val * this.pageSize)
},

Change the number of events

// val每页显示多少条
handleSizeChange(val) {
    
    
  this.dataForm.pageSize=val;
  this.dataList = this.tableData.slice((this.currentPage - 1) * val, this.currentPage * val)
},

Guess you like

Origin blog.csdn.net/qq_46123200/article/details/131949815