递归生成表格动态表头

发布时间 2023-07-12 11:08:45作者: 程序媛CC

<render-column :columnList="headList"></render-column>

<el-table-column>
  <template v-for="(item, index) in columnList">
    <el-table-column v-if="item.child && item.child.length > 0" :key="index" :label="item.name>
      <render-column :columnList="item.child">
        <template v-for="(index1, name) in $scopedSlots" v-slot:[name]="data">
         <slot :name="name" v-bind="data"></slot>
        </template>
      </render-column>
    </el-table-column>
    <el-table-column v-else :prop="item.id :label="item.name :key="index">
      <template slot-scope="scope">
        <span v-if="$scopedSlots[item.id]">
         <slot :name="item.id" v-bind="svope"></slot>
        </span>
      </template>
    </el-table-column>
  </template>
</el-table-column>

参考:https://zhuanlan.zhihu.com/p/617182749