vue 实现滚动到页面底部开始加载更多


scrollTop 页面滚动的高度,
clientHeight 可视区域高度
scrollHeight 可滚动内容的高度

 

mounted(){
  // 添加滚动事件,检测滚动到页面底部
    window.addEventListener('scroll', this.scrollBottom)
  },

// 滚动到页面底部时,请求内容
scrollBottom() { this.loading = false let scrollTop = document.documentElement.scrollTop || document.body.scrollTop; let clientHeight = document.documentElement.clientHeight; let scrollHeight = document.documentElement.scrollHeight; let bottomOfWindow = scrollTop + clientHeight >= scrollHeight-4 console.log(scrollHeight) if (scrollTop!=0&&bottomOfWindow && this.loading == false &&this.finished == false) { this.loading = true this.offset = this.offset + this.limit; let param = { offset: this.offset, limit: this.limit } getArea(param).then((res) => { if (res.code == 200) { this.loading = false this.area = this.area.concat(res.data); //追加数据 if (res.data.length == 0) { //数据全部加载完成 this.finished = true; } else { this.finished = false; } } }) } }

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM