关于在vue2中实现el-table的表头合并

要实现的效果:

代码实现:

设置一下表格的:header-cell-style="rowClass"

复制代码
 <el-table
        :data="tableDataDetail"
        style="width: 100%"
        height="100%"
        :header-cell-style="rowClass"
      >
        <el-table-column label="考核内容" align="center">
          <el-table-column prop="type" label="" width="100" align="center">
          </el-table-column>
          <el-table-column prop="name" label="" align="center">
          </el-table-column>
        </el-table-column>
</el-table>

methods:{
    rowClass({ row, column,rowIndex,columnIndex}) {
        console.log(row,column,rowIndex,columnIndex);
        if(rowIndex===0 && columnIndex===0) {
          this.$nextTick(()=> {
            if(document.getElementsByClassName(column.id).length!==0) {
              document.getElementsByClassName(column.id)[0].setAttribute('rowSpan',2);
              return false
            }
          })
        }
        if(rowIndex===1 && (columnIndex===0 || columnIndex===1)) {
         return {display:'none'}
        }

      },
}

借鉴文章:elementui 表头合并,两列共用一个表头,header-cell-style设置表头样式_el-table两列公用一个title-CSDN博客

相关推荐
yuanyxh7 小时前
Mac 软件推荐
前端·javascript·程序员
万少7 小时前
AtomCode开发微信小程序《谁去呀》 全流程
前端·javascript·后端
学Linux的语莫10 小时前
Vue 3 入门教程
前端·javascript·vue.js
怕浪猫10 小时前
第一章、Chrome DevTools Protocol (CDP) 详解
前端·javascript·chrome
qq43569470112 小时前
Vue04
前端·vue.js
Yeats_Liao13 小时前
Feed流系统设计(三):数据模型与存储设计,从表结构到Redis收件箱
java·javascript·redis
我是真菜13 小时前
彻底理解js中的深浅拷贝
前端·javascript
尽兴-15 小时前
4.1 智能体核心:Agent、Sub-Agent、ReAct、规划执行
前端·javascript·react.js·agent·react·subagent
万物更新_15 小时前
vue框架
前端·javascript·vue.js·笔记
Richar15 小时前
Object.freeze()注意事项
前端·javascript