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