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"
            }
          ]
        }
      ]
相关推荐
努力往上爬de蜗牛1 小时前
react native真机调试
javascript·react native·react.js
y***86692 小时前
TypeScript在Electron应用中的使用
javascript·typescript·electron
zy happy4 小时前
若依 vue3 报错:找不到模块“@/api/xxxx/xxxxx”或其相应的类型声明。。Vue 3 can not find mod
前端·javascript·vue.js
meichaoWen5 小时前
【Vue3】vue3的全面学习(一)
前端·javascript·学习
Q***l6876 小时前
Vue增强现实案例
前端·vue.js·ar
b***74887 小时前
Vue开源
前端·javascript·vue.js
ByteCraze8 小时前
我整理的大文件上传方案设计
前端·javascript
前端小白۞8 小时前
vue2 md文件预览和下载
前端·javascript·vue.js
u***u6859 小时前
Vue云原生
前端·vue.js·云原生
OpenTiny社区9 小时前
TinyEngine 低代码实时协作揭秘:原理 +实操,看完直接用!
前端·vue.js·低代码