小編給大家分享一下javascript如何監(jiān)聽element-ui table滾動事件,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
背景:做管理平臺的項目,用到了element-ui,需要通過監(jiān)聽el-table滾動的位置來獲取最新的數(shù)據(jù),那么怎么樣監(jiān)聽el-table的滾動呢?
準備:我們默認的技術(shù)棧是 vue+element-ui
template代碼:
<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>
綁定監(jiān)聽事件
mounted() { // 獲取需要綁定的table this.dom = this.$refs.table.bodyWrapper this.dom.addEventListener('scroll', () => { // 滾動距離 let scrollTop = this.dom.scrollTop // 變量windowHeight是可視區(qū)的高度 let windowHeight = this.dom.clientHeight || this.dom.clientHeight // 變量scrollHeight是滾動條的總高度 let scrollHeight = this.dom.scrollHeight || this.dom.scrollHeight if (scrollTop + windowHeight === scrollHeight) { // 獲取到的不是全部數(shù)據(jù) 當滾動到底部 繼續(xù)獲取新的數(shù)據(jù) if (!this.allData) this.getMoreLog() console.log('scrollTop', scrollTop + 'windowHeight', windowHeight + 'scrollHeight', scrollHeight) } }) }
獲取到新的數(shù)據(jù)后,調(diào)整滾動條的位置
getMoreLog() { ... this.dom.scrollTop = this.dom.scrollTop - 100 ... }
結(jié)語:至此我們已經(jīng)完成了對table的綁定!
以上是“javascript如何監(jiān)聽element-ui table滾動事件”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對大家有所幫助,如果還想學習更多知識,歡迎關(guān)注創(chuàng)新互聯(lián)網(wǎng)站制作公司行業(yè)資訊頻道!
分享文章:javascript如何監(jiān)聽element-uitable滾動事件-創(chuàng)新互聯(lián)
文章位置:http://www.chinadenli.net/article0/dcshoo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、App設(shè)計、外貿(mào)建站、外貿(mào)網(wǎng)站建設(shè)、網(wǎng)站制作、網(wǎng)站維護
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容