首先给el-table 的外层div 绑定@mouseover='mouseover' @mouseout='mouseout' 鼠标移入移出事件
mouseover() {
clearInterval(this.tabletimer)
},
mouseout() {
this.autoScroll(false)
},
autoScroll(init) {
this.$nextTick(() => {
const t = 80
const box = this.$el.querySelector('.el-tablebody-wrapper')
const content = this.$el.querySelector('.el-table
body')
if (init) box.scrollTop = 0
this.tabletimer = setInterval(() => {
this.rollStart(box, content)
}, t)
})
},
rollStart(box, content) {
if (box.scrollTop >= (content.scrollHeight - box.offsetHeight)) {
box.scrollTop = 0
} else {
box.scrollTop++
}
},