列数不固定时怎么使用el-tabel展示数据

时间:2021-07-10 06:54:51
<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','女']
          】