使用el-tabel当列数不固定时如何展示数据

2023-03-26  本文已影响0人  为什么划船不靠桨

最近遇到一个需求,el-tabel展示数据,列表的列数是不固定的,显示多少列及列的头部内容都是从接口请求下来的,这样的情况下如何展示,从网上找了下,原来实现起来很简单,感谢前辈们之前总结!!!

<el-table :data="contents" stripe>
        <el-table-column v-for="(item, index) in contentsTitle" :key="index" :label="item">
          <template scope="scope">
            <span>{{scope.row[index]}}</span>
          </template>
        </el-table-column>
</el-table>

contentsTitle为表头名称,contents是二元数组,每个scope.row是与contentsTitle对应的字符串数组。

contentsTitle=['名称','年龄','性别']
contents = [
    ['小名','23','男'],
    ['小红','20','女'],
    ['小樱','19','女']
]
上一篇 下一篇

猜你喜欢

热点阅读