created的时候添加上事件
window.addEventListener('scroll',this.bodyScroll)
bodyScroll () {
let scrollTop =document.documentElement.scrollTop ||document.body.scrollTop
let clientHeight =document.documentElement.clientHeight ||document.body.clientHeight
let scrollHeight =document.documentElement.scrollHeight ||document.body.scrollHeight
if ((clientHeight >0 &&scrollTop >0) && (scrollTop +clientHeight ===scrollHeight)) {
if (!this.finished) {this.getListData(true) }
}
}
离开组件的时候要销毁 滚动事件
destroyed () { // 销毁滚动加载 window.removeEventListener('scroll', this.bodyScroll)}
网友评论