我目前正在开发我的应用程序。我正在使用 vue v2 我正在尝试创建一个动态表,我可以在单击按钮时添加行和子行。目前我可以毫无问题地插入行,但如果 1 个单元格的长文本占用 2 行,它就会搞砸
我正在努力实现这一目标:
这是我目前的结果:
<button @click="addMe">add row</button>
<table>
<thead>
<tr title="first">
<th style="width:50px">cell1</th>
<th style="width:150px">cell2</th>
<th>cell3</th>
<th>cell4</th>
<th>cell5</th>
<th>cell6</th>
<th>cell7</th>
<th>cell8</th>
<th>cell9</th>
<th>cell10</th>
</tr>
</thead>
<tbody>
<tr v-for="item in data" :key="item.id">
<td>{{ item.id }}</td>
<td>{{ item.name }}</td>
<td>{{ item.score }}</td>
<td>{{ item.profile }}</td>
<td class="new-td">
<tr v-for="item in list" :key="item">
<td>
row1
superlongtextcell5
</td>
</tr>
</td>
<td class="new-td">
<tr v-for="item in list" :key="item">
<td>
row1
cell6
</td>
</tr>
</td>
<td class="new-td">
<tr v-for="item in list" :key="item">
<td>
row1
cell7
</td>
</tr>
</td>
<td class="new-td">
<tr v-for="item in list" :key="item">
<td>
row1
cell8
</td>
</tr>
</td>
<td class="new-td">
<tr v-for="item in list" :key="item">
<td>
row1
cell9
</td>
</tr>
</td>
<td class="new-td">
<tr v-for="item in list" :key="item">
<td>
row1
cell10
</td>
</tr>
</td>
</tr>
</tbody>
</table>
data() {
return {
list: [1],
data: [
{ name: "row1 cell1" },
{ name: "row2 cell1" },
{ name: "row3 cell1" },
{ name: "row4 cell1" },
{ name: "row5 cell1" }
]
}
},
methods: {
addMe() {
this.list.push(1);
}
}
有可能吗?谢谢你