数据下拉加载

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)
},

浙公网安备 33010602011771号