监听element-ui table滚动事件的方法
2019/6/26 23:10:01
本文主要是介绍监听element-ui table滚动事件的方法,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
背景
做管理平台的项目,用到了element-ui,需要通过监听el-table滚动的位置来获取最新的数据,那么怎么样监听el-table的滚动呢?
准备
我们默认的技术栈是 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>
绑定监听事件
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的绑定! 希望对大家的学习有所帮助,也希望大家多多支持找一找教程网。
这篇关于监听element-ui table滚动事件的方法的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-30React Native常用组件-点击组件
- 2024-05-30uniapp+vue3+uv-ui手机端后台OA管理模板
- 2024-05-29Python网络爬虫的时候json=就是让你少写个json.dumps()
- 2024-05-27React Native常用组件-展示组件
- 2024-05-27React Native常用组件-列表组件
- 2024-05-09vue3开发前端表单缓存自定义指令,移动端h5必备插件
- 2024-05-09React Hooks在class组件中的使用方式
- 2024-03-30[OIDC in Action] 2. 基于OIDC(OpenID Connect)的SSO(纯JS客户端)
- 2024-03-29terraform jsonencode
- 2024-03-13vuex-persist