ant-design-vue tabel x,y都设置滚动后错位的解决方法


通过自定义指令fit-columns来解决
ellipsis设置true
function adjustColumnWidth(table) {
  const thead = table.querySelector('thead');
  const tbody = table.querySelector('tbody');
  const headList = [];
  const bodyList = [];
  const widthList = [];
  thead.querySelectorAll('th').forEach(item => {
    headList.push(item.querySelector('span').offsetWidth + 18);
  });
  tbody
    .querySelector('tr')
    .querySelectorAll('td')
    .forEach((item, index) => {
      const bodyWidth = item.offsetWidth;
      let width = bodyWidth;
      bodyList.push(bodyWidth);
      if (bodyWidth < headList[index]) {
        width = headList[index];
      }
      item.style.minWidth = `${width}px`;
      thead.querySelectorAll('th')[index].style.minWidth = `${width}px`;
      widthList.push(width);
    });
}
Vue.directive('fit-columns', {
  componentUpdated(el) {
    setTimeout(() => {
      adjustColumnWidth(el);
    }, 200);
  },
});


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM