作管理平臺的項目,用到了element-ui,須要經過監聽el-table滾動的位置來獲取最新的數據,那麼怎麼樣監聽el-table的滾動呢?
咱們默認的技術棧是 vue+element-ui
<el-table :data="logList" :show-header="false" row-class-name="table-row-class" height="700" ref="table" @row-click="rowClick"> <el-table-column type="expand"> <el-table-column label="log信息" prop="message"> </el-table-column> </el-table>
mounted() { // 獲取須要綁定的table this.dom = this.$refs.table.bodyWrapper this.dom.addEventListener('scroll', () => { // 滾動距離 let scrollTop = this.dom.scrollTop // 變量windowHeight是可視區的高度 let windowHeight = this.dom.clientHeight || this.dom.clientHeight // 變量scrollHeight是滾動條的總高度 let scrollHeight = this.dom.scrollHeight || this.dom.scrollHeight if (scrollTop + windowHeight === scrollHeight) { // 獲取到的不是所有數據 當滾動到底部 繼續獲取新的數據 if (!this.allData) this.getMoreLog() console.log('scrollTop', scrollTop + 'windowHeight', windowHeight + 'scrollHeight', scrollHeight) } }) }
getMoreLog() { ... this.dom.scrollTop = this.dom.scrollTop - 100 ... }
至此咱們已經完成了對table的綁定!vue