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