elment Table多级表头固定列后,合计行错位显示问题解决

复制代码
<el-table-column :label="tabsDataFilters1.orgName" width="370" :fixed="tableFixed">
  <el-table-column type="index" label="序号" width="50" align="center" :fixed="tableFixed"></el-table-column>
  <el-table-column prop="name" label="姓名" width="200" align="left" :fixed="tableFixed"></el-table-column>
  <el-table-column prop="age" :formatter="formatAmount" label="小计" width="120" align="center" :fixed="tableFixed"></el-table-column>
</el-table-column>

mounted进行监听,监听方法如下:

observeClassChanges() {
  debugger
  this.$nextTick(() => {
    const bodyWrapper = this.$refs.table1.$el.querySelector('.el-table__body-wrapper');
    if (!bodyWrapper) return;

    // 创建 MutationObserver 监听 class 变化
    this.observer = new MutationObserver((mutationsList) => {
      for (const mutation of mutationsList) {
        if (mutation.attributeName === 'class') {
          this.removeScrollingClasses(bodyWrapper);
        }
      }
    });

    // 监听 `class` 变化
    this.observer.observe(bodyWrapper, {
      attributes: true,
      attributeFilter: ['class'],
    });

    // 初始移除 class,防止渲染时已有
    this.removeScrollingClasses(bodyWrapper);
  });
},
// 滚动中间行样式移除
removeScrollingClasses(bodyWrapper) {
  if (bodyWrapper.classList.contains('is-scrolling-middle')) {
    bodyWrapper.classList.remove('is-scrolling-middle');
  }
  if (bodyWrapper.classList.contains('is-scrolling-left')) {
    bodyWrapper.classList.remove('is-scrolling-left');
  }
},
相关推荐
Penge6667 小时前
JavaScript:BOM 详解
前端
梯度下降者7 小时前
Nuxt框架
vue.js·服务端渲染·全栈开发·混合渲染·nuxt框架
Penge6667 小时前
Vite vs Webpack:前端构建工具原理与实战
前端
Penge6667 小时前
前端包管理工具:npm、Yarn、pnpm 快速入门
前端
Penge6668 小时前
Sass 了解
前端
Penge6668 小时前
Webpack 打包从 0 到 1 实战笔记
前端
Penge6668 小时前
Webpack 入门:是什么、为什么需要、怎么使用?
前端
Penge6668 小时前
Ant Design(Antd)了解
前端
wangruofeng9 小时前
同一行代码,百种渲染:Asuka、React Native 与 Flutter 跨平台渲染机制深度拆解
前端·github
Penge6669 小时前
JavaScript 核心语法速通
前端