通过自定义指令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);
  },
});

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-03
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-02-21
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-02
相关资源
相似解决方案