我为此做了一个代码笔。希望这对将来的人有所帮助。
https://codepen.io/anon/pen/YgdKzm
由于默认情况下该功能不可用,我们必须编写一些自定义代码。基本上你假设第一行总是包含标题。
const tableData = [
['Date', 'Name', 'Address'],
['2016-05-03', 'Tom', 'No. 189, Grove St, Los Angeles1'],
['2016-05-02', 'James', 'No. 189, Grove St, Los Angeles2'],
['2016-05-03', 'Alice', 'No. 189, Grove St, Los Angeles3'],
['2016-05-02', 'John', 'No. 189, Grove St, Los Angeles4']
]
<el-table
border
:data="tableData.slice(1)">
<!--Assuming the first row always contains the table header-->
<el-table-column
v-for="(column, index) in tableData[0]"
:key="index
:label="column">
<template slot-scope="scope">
{{ scope.row[index] }}
</template>
</el-table-column>
</el-table>
slice 函数将返回一个新数组而不修改原始数组,我们可以使用 slot-scope 迭代和呈现自定义内容。