//给两个table 绑定ref属性
scroll () {
let table1 = this.$refs.table1.bodyWrapper // 上表格
let table2 = this.$refs.table2.bodyWrapper // 下表格
table2.addEventListener('scroll', () => {
// 滚动监听事件
table1.scrollLeft = table2.scrollLeft
this.$nextTick(() => {
// 表格滚动时有一定概率发生错位,这里使用doLayout方法,来解决重新布局的问题
this.$refs.table1.doLayout()
this.$refs.table2.doLayout()
})
})
//然后隐藏上面子表格的滚动条即可
<style lang="less">
.Tableone
::-webkit-scrollbar, ::-webkit-scrollbar-track, ::-webkit-scrollbar-thumb{
display none
}
</style>
Vue 两个el-table合并同时横向滚动
于 2021-10-15 10:57:23 首次发布