表格上下滚动条

1.html代码:

<div ref="topScroll" class="top-scroll" @scroll="handleScrollTop"
     v-if="ifRefresh && tableType==='baseAndSpecialTableTitle'">
  <div class="top-scroll-content" :style="tableWidth"></div>
</div>

2.handleScrollTop方法:
tableWidth: {width: 0}

handleScrollTop() {
  if (this.$refs.topScroll) {
    let scrollLeft = this.$refs.topScroll.scrollLeft
    this.$refs.multipleTable.bodyWrapper.scrollTo(scrollLeft, 0);
  }
}

3.获取表格异步添加滚动事件:

 getTableData() {
    this.loading = true
    this.tableData = []
    delete this.params.startYear
    delete this.params.endYear
    achievementsApi.getTableDataApi(this.params).then(res => {
      this.loading = false
      this.tableData = res.data.result.rows
      this.tableTotal = res.data.result.total
      setTimeout(() => {
        if (this.$refs.multipleTable) {
          this.tableWidth.width = this.$refs.multipleTable.bodyWrapper.scrollWidth + 'px'
          this.$refs.multipleTable.doLayout()

          this.tableDom = this.$refs.multipleTable.bodyWrapper
          this.tableDom.addEventListener('scroll', () => {
            // 滚动距离
            let scrollLeft = this.tableDom.scrollLeft
            this.$refs.topScroll.scrollTo(scrollLeft, 0);
          })
        }
      }, 500)
    }).catch(err => {
      this.loading = false
    })
  }

4.css代码:

/*顶部滚动条*/
  .top-scroll {
    overflow-x: auto;
    overflow-y: hidden;

    .top-scroll-content {
      background-color: #fff;
      height: 1px;
    }
  }
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值