转自链接,https://blog.csdn.net/m0_37893932/article/details/107333312,核心代码:
1 methods: { 2 loadData() { 3 console.log(‘getData‘) 4 //这里模拟请求数据,最后一页数据不够pageSize时有BUG,暂不处理 5 let data = jsonData.splice((this.currentPage - 1) * this.pageSize, this.pageSize) 6 this.tableData = this.tableData.concat(data); 7 console.log("表格数据量:",this.tableData.length) 8 }, 9 tableListener() { 10 console.log("监听表格dom对象的滚动事件") 11 let that = this; 12 let dom = that.$refs.myTable.bodyWrapper 13 dom.addEventListener("scroll", function () { 14 const scrollDistance = dom.scrollHeight - dom.scrollTop - dom.clientHeight; 15 // console.log("scroll", scrollDistance) 16 if (scrollDistance <= 0) {//等于0证明已经到底,可以请求接口 17 if (that.currentPage < that.totalPage) {//当前页数小于总页数就请求 18 that.currentPage++;//当前页数自增 19 //请求接口的代码 20 that.loadData() 21 } 22 } 23 }) 24 } 25 }
原文:https://www.cnblogs.com/RioPlus/p/14384313.html