表格滚动分页查询

1.给表格添加id,height="100%"是固定表头

<el-table

id="attr-table-box"

height="100%"

:row-style="{ height: '66px' }"

style="width: 100%; height: 100%; "

>

2.使用计算属性获取总页数

computed: {

// 表格总页数,控制滚动查询 attrTotal是数据总数;

attrTotalPage() {

return Math.ceil(this.attrTotal / this.queryParamsAttr.pageSize);

},

},

3.主要方法
javascript 复制代码
// 属性表格绑定滚动事件,滚动分页查询
    queryByScroll() {
      const _this = this;
      const tableScrollDom =
        document.getElementById("attr-table-box").childNodes[2];
      tableScrollDom.addEventListener("scroll", function () {
        const scrollTop = tableScrollDom.scrollTop;
        const clientHeight = tableScrollDom.clientHeight;
        const scrollHeight = tableScrollDom.scrollHeight;
        if (scrollTop + clientHeight == scrollHeight) {
          // 滚动到底部
          if (_this.attrTotalPage > _this.queryParamsAttr.pageNum) {
            // 如果当前还没到最后一页,滚动到底部以后继续查询
            _this.queryParamsAttr.pageNum++;
            // 请求数据
            _this.getAttrData();
          }
        } else {
        }
      });
    },
4.在mounted里调用

mounted() {

this.queryByScroll();

},

相关推荐
于慨17 分钟前
Capacitor
前端
该怎么办呢20 分钟前
Source/Core/Event.js
开发语言·javascript·ecmascript·cesium
IT凝冬40 分钟前
liunx 的 centos7 安装ngin
前端
赵锦川41 分钟前
大屏比例缩放
前端·javascript·html
该怎么办呢1 小时前
Source/Core/DeveloperError.js
开发语言·javascript·ecmascript
于慨1 小时前
tauri
java·服务器·前端
riyue6661 小时前
封装 WebSocket 工具类
网络·vue.js·websocket·网络协议·v
贼爱学习的小黄2 小时前
NC BIP参照开发
java·前端·nc
weixin_462901972 小时前
ESP32 LED控制代码解析
javascript
小江的记录本2 小时前
【MyBatis-Plus】MyBatis-Plus的核心特性、条件构造器、分页插件、乐观锁插件
java·前端·spring boot·后端·sql·tomcat·mybatis