组件中的el-table监听滚动条实现数据懒加载

el-table表格组件部分代码


watch: {
    
    
//监听滚动
    tableDom (newVal) {
    
    
      if (newVal) {
    
    
        this.tableDom = newVal
        this.tableDom.addEventListener('scroll', (res) => {
    
    
          let height = res.target;
          let clientHeight = height.clientHeight;
          let scrollTop = height.scrollTop;
          let scrollHeight = height.scrollHeight;
          if (clientHeight + scrollTop + 585 > scrollHeight) {
    
    
            // 请求下一页
            this.currentPages = this.currentPages + 1
            if (this.currentPages < this.totalPage) {
    
    
              this.$emit('getProvidersTableData', this.currentPages);
            }
          }

        }, true);
      };
    }
  },
//组件被打开的方法
dialogOpen () {
    
    
      this.dialogVisible = true
      // 将已选择的人员在表格中勾选
      this.$nextTick(() => {
    
    
      //获取table节点
        this.tableDom = this.$refs.ProvidersTable.bodyWrapper
        
      })
    },

猜你喜欢

转载自blog.csdn.net/weixin_45324044/article/details/121700578