需求:當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)