You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.09 09:05:23