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"
            }
          ]
        }
      ]
相关推荐
yuezhilangniao4 小时前
AI智能体全栈开发工程化规范 备忘 ~ fastAPI+Next.js
javascript·人工智能·fastapi
~牧马~5 小时前
【记录63】electron打包vue项目之踩坑
vue.js·electron·electron与node兼容
铅笔侠_小龙虾5 小时前
Flutter Demo
开发语言·javascript·flutter
2501_944525545 小时前
Flutter for OpenHarmony 个人理财管理App实战 - 账户详情页面
android·java·开发语言·前端·javascript·flutter
计算机学姐5 小时前
基于SpringBoot的电影点评交流平台【协同过滤推荐算法+数据可视化统计】
java·vue.js·spring boot·spring·信息可视化·echarts·推荐算法
wangdaoyin20106 小时前
若依vue2前后端分离集成flowable
开发语言·前端·javascript
天天进步20156 小时前
AI Agent 与流式处理:Motia 在生成式 AI 时代的后端范式
javascript
心柠6 小时前
vue3相关知识总结
前端·javascript·vue.js
a1117767 小时前
图书借阅管理系统(FastAPI + Vue)
前端·vue.js·fastapi
常年游走在bug的边缘7 小时前
掌握JavaScript作用域:从函数作用域到块级作用域的演进与实践
开发语言·前端·javascript