關於ElementUI的table滾動加載數據的處理


需求:當tableData大於20條數據時,只加載20條數據。滾動到表格底部再加載20條數據直至所有數據加載完成

解決:

給el-table標簽添加ref:table

this.$refs.table.bodyWrapper.addEventListener('scroll', (res) => { // 監聽滾動事件
        const height = res.target

        const clientHeight = height.clientHeight // 表格視窗高度 即wraper
        const scrollTop = height.scrollTop // 表格內容已滾動的高度
        const scrollHeight = height.scrollHeight // 表格內容撐起的高度
        if (clientHeight + scrollTop === scrollHeight) {
          // 表格滾動已經觸底 更新表格數據
     // this.times += 1
   // const length = 20*this.times > this.baseData.length ?  this.baseData.length : 20*this.times
   // this.tableData = this.baseData.slice(0,length)
        }
      }, true)


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM