gpt4 book ai didi

html - Vue 组件返回多个表行

转载 作者:行者123 更新时间:2023-12-04 14:25:16 25 4
gpt4 key购买 nike

我试图从单个组件 v-design-row 返回两个 tr 元素。我知道 vue 要求将模板元素包装在一个 div 中,但我不能将它们包装在一个 div 中,因为 html 表需要标签结构。当我在 v-design-row 组件中添加第二个 tr 时,vue 不会呈现任何内容。

谁能建议实现这一目标的最佳方法?

主.vue

   <table class="table">
<thead>
<th>Image</th>
<th>Name</th>
<th>Description</th>
<th>Status</th>
<th>Order</th>
<th>Edit</th>
<th>Delete</th>
</thead>
<tbody v-for="catagory in catagories">
<v-catagory-row :catagory="catagory"></v-catagory-row>
<v-design-row v-for="design in catagory.designs" :design="design"></v-design-row>
</tbody>
</table>

v-design-row.vue

<template>
<tr>
<td><img :src="design.image_directory" :alt="design.name"></td>
<td>{{ design.name }}</td>
<td>
<button class="btn btn-secondary" type="button" data-toggle="collapse" :data-target="'#' + design.identifier" aria-expanded="false" :aria-controls="design.identifier">
<i class="fa fa-plus" aria-hidden="true"></i> Show
</button>
</td>
<td>
<div class="switch">
<input :id="'active'+design.id" v-model="design.active" class="btn-toggle btn-toggle-round-flat" type="checkbox">
<label :for="'active'+design.id"></label>
</div>
</td>
<td>
<button class="btn btn-secondary" type="button">
<i class="fa fa-caret-up" aria-hidden="true"></i>
</button>
<button class="btn btn-secondary" type="button">
<i class="fa fa-caret-down" aria-hidden="true"></i>
</button>
{{ design.sort_order }}
</td>
<td>
<button class="btn btn-secondary" type="button">
<i class="fa fa-pencil" aria-hidden="true"></i>
</button>
</td>
<td>
<button class="btn btn-secondary" type="button">
<i class="fa fa-trash" aria-hidden="true"></i>
</button>
</td>
</tr>
<tr>
<td class="p-0" colspan="7">
<div class="collapse" :id="design.identifier">
<div class="p-3">
{{ design.description }}
</div>
</div>
</td>
</tr>
</template>

最佳答案

您可以使用多个 <tbody> 对行进行分组像这样的部分:

<table>
<thead>
<tr> ... </tr>
</thead>
<tbody>
<tr> ... </tr>
<tr> ... </tr>
</tbody>
<tbody>
<tr> ... </tr>
<tr> ... </tr>
</tbody>
</table>

您可以通过使用 <tbody> 在模板中使用它作为根元素:

<template>
<tbody>
<tr> ... </tr>
<tr> ... </tr>
</tbody>
</template>

关于html - Vue 组件返回多个表行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46893445/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com