antd table 表格上下错位

图片描述
如图,表格上下错位,调出控制台上下拉一下又好了,请问这个如何处理

阅读 14.3k
6 个回答

你这个问题解决了吗?如果fixed取消掉的话,那就达不到固定的效果了,只有加了fixed才会出现这个问题。

.ant-table-tbody > tr > td {

word-wrap: break-word;
word-break: break-all;

}

新手上路,请多包涵
  .ant-table-fixed-header .ant-table-body-inner {
    overflow: hidden; // 很重要
  }

3版本的antd应该这么设置就好了

这表格不是用table写的吧

.ant-table-fixed {
    tr {
        height: auto !important;
    }
}

数据渲染完调用一下这个方法同步高度就可以了。
注意 this.$el,是当前表格的父容器,如果页面存在多个表格,需要替换为指定表格的父容器

methods: {
    // 同步行高
    syncRowHeights() {
      this.$nextTick(() => {
        const fixedRows = this.$el.querySelectorAll('.ant-table-fixed-left .ant-table-tbody > tr')
        const scrollRows = this.$el.querySelectorAll('.ant-table-scroll .ant-table-tbody > tr')
        fixedRows.forEach((fixedRow, index) => {
          const scrollRow = scrollRows[index]
          const maxHeight = Math.max(fixedRow.offsetHeight, scrollRow.offsetHeight)
          fixedRow.style.height = `${maxHeight}px`
          scrollRow.style.height = `${maxHeight}px`
        })
      })
    },
}
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进