Code example for listening to element-ui table scroll events

不言
Release: 2019-03-26 10:29:48
forward
3527 people have browsed it

What this article brings to you is a code example for monitoring element-ui table scrolling events. It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you. help.

Background: When working on a management platform project, element-ui is used, and the latest data needs to be obtained by monitoring the scrolling position of the el-table. So how to monitor the scrolling of the el-table?

Preparation: Our default technology stack is vue element-ui

template code:

    
Copy after login

Binding listening event

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) } }) }
Copy after login

obtained After adding the new data, adjust the position of the scroll bar

getMoreLog() { ... this.dom.scrollTop = this.dom.scrollTop - 100 ... }
Copy after login

Conclusion: So far we have completed the binding to the table!

This article has ended here. For more other exciting content, you can pay attention to theJavaScript Video Tutorialcolumn on the PHP Chinese website!

The above is the detailed content of Code example for listening to element-ui table scroll events. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!