el-table滚动加载下一页

// 获取表格对象
  let dom = document.querySelector(".el-table__body-wrapper");
  let that = this;
  dom.addEventListener("scroll", () =>{
    if(!that.addLoading) {
      const scrollDistance =
          dom.scrollHeight - dom.scrollTop - dom.clientHeight;
         // 判断是否到底,可以加载下一页
         if (scrollDistance <= 0) {
           // 判断是否全部加载完成
           if (that.pageParams.page >= that.totalPage) {
             that.$message.warning("已经见底了 ~");
           }
           if (that.pageParams.page < that.totalPage) {
             that.addLoading = true;
             //当前页数小于总页数就请求
             that.pageParams.page++; //当前页数自增
             // 加载下一页方法
             that.getNextList();
           }
         }
       }
    });

把以上代码放在mounted()里,就可以运行啦

你可能感兴趣的:(javascript,vue.js,前端)