【发布时间】:2021-07-24 04:55:39
【问题描述】:
嘿,我对 Vue 和 JavaScript 还很陌生,我想创建一个 Html 表。对于我的软件,我想要一个 Table.vue 组件,它可以向我显示不同的表格,如下所示。
{
"id": 1,
"text": "Hello"
}
{
"id": 1,
"status": "damaged",
"info": "test",
"text": "content"
}
如何动态获取这些不同表格的列以及如何显示它们?
<template>
<table class="table">
<thead>
<tr>
<th v-for="(column, index) in columns" :key="index"> {{column}}</th>
</tr>
</thead>
<tbody>
<tr v-for="(item, index) in items" :key="index">
<td v-for="(column, indexColumn) in columns" :key="indexColumn">{{item[column]}}</td>
</tr>
</tbody>
</table>
</template>
data() {
return {
items: [],
columns: []
}
}
【问题讨论】:
标签: javascript html arrays vue.js