el-table 多级表头

1.结构

复制代码
<el-table
        :data="tableData"
        border
        :height="700"
        style="width: 100% !important; overflow: auto"
        :header-cell-style="{ background: '#becee1', color: '#333' }"
        :cell-style="{ padding: '5px' }"
      >
        <template v-for="item in tableHeader">
          <template v-if="item.children && item.children.length > 0">
            <el-table-column
              :key="item.id"
              :label="item.label"
              :prop="item.label"
              align="center"
            >
              <span v-for="subItem in item.children" :key="subItem.id">
                <el-table-column
                  :label="subItem.label"
                  :prop="subItem.prop"
                  align="center"
                ></el-table-column>
              </span>
            </el-table-column>
          </template>
          <el-table-column
            v-else
            :key="item.id"
            :label="item.label"
            :prop="item.prop"
            align="center"
          ></el-table-column>
        </template>
      </el-table>

2.数据

复制代码
tableData: [
        {
          fenju: "杨浦分局",
          tianxie: "已填写",
          prop11: "11",
          prop12: "12",
          prop21: "21",
          prop22: "22",
          prop31: "31",
          prop32: "32"
        },
        {
          fenju: "长宁分局",
          tianxie: "未填写",
          prop11: "11",
          prop12: "12",
          prop21: "21",
          prop22: "22",
          prop31: "31",
          prop32: "32"
        }
      ],
      tableHeader: [
        {
          label: "分局",
          prop: "fenju"
        },
        {
          label: "填写情况",
          prop: "tianxie"
        },
        {
          id: 1,
          label: "考核组1",
          prop: "",
          children: [
            {
              id: 11,
              label: "考核项1",
              prop: "prop11"
            },
            {
              id: 12,
              label: "考核项2",
              prop: "prop12"
            }
          ]
        },
        {
          id: 2,
          label: "考核组2",
          prop: "",
          children: [
            {
              id: 21,
              label: "考核项1",
              prop: "prop21"
            },
            {
              id: 22,
              label: "考核项2",
              prop: "prop22"
            }
          ]
        },
        {
          id: 3,
          label: "考核组3",
          prop: "",
          children: [
            {
              id: 11,
              label: "考核项1",
              prop: "prop31"
            },
            {
              id: 12,
              label: "考核项2",
              prop: "prop32"
            }
          ]
        }
      ]
相关推荐
前端程序猿之路2 小时前
Next.js 入门指南 - 从 Vue 角度的理解
前端·vue.js·语言模型·ai编程·入门·next.js·deepseek
D_C_tyu2 小时前
Vue3 + Element Plus | el-table 表格获取排序后的数据
javascript·vue.js·elementui
JIngJaneIL2 小时前
基于java+ vue农产投入线上管理系统(源码+数据库+文档)
java·开发语言·前端·数据库·vue.js·spring boot
天外天-亮3 小时前
v-if、v-show、display: none、visibility: hidden区别
前端·javascript·html
hellotutu3 小时前
vue2 从 sessionStorage 手动取 token 后,手动加入到 header
vue.js·token·session·header
沿着路走到底4 小时前
JS事件循环
java·前端·javascript
子春一24 小时前
Flutter 2025 可访问性(Accessibility)工程体系:从合规达标到包容设计,打造人人可用的数字产品
前端·javascript·flutter
jlspcsdn5 小时前
20251222项目练习
前端·javascript·html
一 乐6 小时前
酒店预约|基于springboot + vue酒店预约系统(源码+数据库+文档)
java·数据库·vue.js·spring boot·后端
前端无涯6 小时前
React/Vue 代理配置全攻略:Vite 与 Webpack 实战指南
vue.js·react.js