如何在Bootstrap Vue表格中传递行对象属性至子组件
解决Bootstrap Vue表格行ID动态传递给自定义组件的问题
你只需要通过row.item访问当前行的数据对象,取出对应的ID字段传给c-action-button组件即可,修改后的代码如下:
<div> <b-table :items="guests" :fields="fields" :sort-by.sync="sortBy" striped responsive="sm" > <template #head(name)="scope"> Nome </template> <template #head(email)="scope"> E-mail </template> <template #cell(action)="row"> <!-- 替换为当前行对象的ID字段,假设字段名为id --> <c-action-button :id="row.item.id" /> </template> </b-table> </div>
补充说明:
- 在Bootstrap Vue的
b-table单元格模板中,row参数包含当前行的上下文信息,row.item就是该行对应的guests数组里的原始数据对象。 - 如果你的数据对象中ID字段不是
id(比如是guestId、userId这类命名),直接把row.item.id改成对应的字段名即可。
内容的提问来源于stack exchange,提问作者Gabriel Edu
相关产品推荐
相关产品推荐

