十年網(wǎng)站開發(fā)經(jīng)驗(yàn) + 多家企業(yè)客戶 + 靠譜的建站團(tuán)隊(duì)
量身定制 + 運(yùn)營(yíng)維護(hù)+專業(yè)推廣+無(wú)憂售后,網(wǎng)站問題一站解決
小編給大家分享一下javascript如何監(jiān)聽element-ui table滾動(dòng)事件,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!

背景:做管理平臺(tái)的項(xiàng)目,用到了element-ui,需要通過監(jiān)聽el-table滾動(dòng)的位置來獲取最新的數(shù)據(jù),那么怎么樣監(jiān)聽el-table的滾動(dòng)呢?
準(zhǔn)備:我們默認(rèn)的技術(shù)棧是 vue+element-ui
template代碼:
綁定監(jiān)聽事件
mounted() {
// 獲取需要綁定的table
this.dom = this.$refs.table.bodyWrapper
this.dom.addEventListener('scroll', () => {
// 滾動(dòng)距離
let scrollTop = this.dom.scrollTop
// 變量windowHeight是可視區(qū)的高度
let windowHeight = this.dom.clientHeight || this.dom.clientHeight
// 變量scrollHeight是滾動(dòng)條的總高度
let scrollHeight = this.dom.scrollHeight || this.dom.scrollHeight
if (scrollTop + windowHeight === scrollHeight) {
// 獲取到的不是全部數(shù)據(jù) 當(dāng)滾動(dòng)到底部 繼續(xù)獲取新的數(shù)據(jù)
if (!this.allData) this.getMoreLog()
console.log('scrollTop', scrollTop + 'windowHeight', windowHeight + 'scrollHeight', scrollHeight)
}
})
}獲取到新的數(shù)據(jù)后,調(diào)整滾動(dòng)條的位置
getMoreLog() {
...
this.dom.scrollTop = this.dom.scrollTop - 100
...
}結(jié)語(yǔ):至此我們已經(jīng)完成了對(duì)table的綁定!
以上是“javascript如何監(jiān)聽element-ui table滾動(dòng)事件”這篇文章的所有內(nèi)容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內(nèi)容對(duì)大家有所幫助,如果還想學(xué)習(xí)更多知識(shí),歡迎關(guān)注創(chuàng)新互聯(lián)網(wǎng)站制作公司行業(yè)資訊頻道!