动态多级别表头-数据渲染

1.代码结构

 <el-table-column width="120" align="center" v-for="colm in changeLabel" :prop="colm.prop" :label="colm.label">
            <el-table-column v-for="item in colm.children" :prop="item.prop" :label="item.label">
              <template #default="scope">
                {{ scope.row[item.prop] }}
              </template>
            </el-table-column>
          </el-table-column>

2.渲染数据结构(changeLabel)的值

[
    {
        "label": "2023年",
        "children": [
            {
                "prop": "2023-8",
                "label": "8月"
            },
            {
                "prop": "2023-9",
                "label": "9月"
            },
            {
                "prop": "2023-10",
                "label": "10月"
            },
            {
                "prop": "2023-11",
                "label": "11月"
            }
        ]
    }
]

循环表头,将:label和:prop赋值,再循环children,数据的渲染就是scope每行数据对应的字段,记得先将表格数据转换成和prop对应的字段

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值