其他分享
首页 > 其他分享> > 数据下拉加载

数据下拉加载

作者:互联网

 

 

class LazyLoad {   constructor(options) {     this.that = options.that     this.className = options.className     this.page = options.page     this.data = options.data     this.func = options.func
    this.onscroll = null     this.scroll = null     this.init()   }   setPageNumber(num) {     this.page.pageNumber = num   }   setTotal(num) {     this.page.total = num   }   init() {     const table = document.querySelector(this.className)     if (table) {       this.scroll = table.querySelector('.ant-table-body')       this.onscroll = (e) => {         if (Math.round(this.scroll.scrollTop) + this.scroll.clientHeight >= this.scroll.scrollHeight) {           if (this.page.pageNumber === Math.ceil(this.page.total / this.page.pageSize)) {             this.that.$message.info('已经到底了!')           } else {             this.page.pageNumber++             this.func.bind(this.that)(this.page.pageNumber)           }         }       }       this.scroll.addEventListener('scroll', this.onscroll)     }   }
  distory() {     if (this.onscroll) {       this.scroll.removeEventListener('scroll', this.onscroll)       this.onscroll = null     }   } }    lazyLoadData(options) {     return new LazyLoad(options)   },

标签:scroll,page,onscroll,num,table,数据,options,加载
来源: https://www.cnblogs.com/eihanhan/p/15882131.html