【发布时间】:2021-06-18 12:02:38
【问题描述】:
我有一个表头:
fields: [
'description',
'potSize',
'price',
],
我有我的表格数据:
testArray: [
{
price: '10,00',
potSize: 'C2',
description: 'desc',
},
{
price: '10,00',
potSize: 'C2',
description: 'rwefv ',
},
{
price: '10,00',
potSize: 'C2',
description: '',
},
],
两者都在表格组件中读取
<thead>
<tr>
<th v-for="item in fields" :key="item">{{ item }}</th>
</tr>
</thead>
<tbody>
<tr v-for="(item, key) in testArray" :key="key">
<td v-for="(keys, col) in item" :key="keys">
{{ item[col] }}
</td>
</tr>
</tbody>
如您所见,标题行和数据行关键不匹配。我需要按标题顺序显示 testArray 键值对。我怎样才能最有效地做到这一点?
【问题讨论】:
标签: javascript arrays vue.js object html-table