el-table表格折叠时,点某行的折叠按钮时子行内容全展开问题,想做到点哪行哪行的子内容才展示

今天遇到了el-table表格折叠时,点某行的折叠按钮时子行内容全展开问题,

想要的是点哪行哪行的子内容才展示,问题解决方案:

1、在ProTable 中加 :row-key="id" (ProTable是封装的el-table)

复制代码
<ProTable
      ref="proTable"
      :columns="columns"
      :data="tableData1"
      :data-callback="dataCallback"
      :tool-button="false"
      :pagination="false"
      :height="490"
      :card="false"
      :key="componentKey"
      :row-key="id"
    >
      <template #operation="scope">
        <el-button type="primary" link :icon="EditPen" @click="openTab(scope.row)">{{
          !scope.row.flag ? t("excel.input") : t("excel.show")
        }}</el-button>
        <el-button type="primary" link :icon="Delete" @click="openDelete(scope.row)">{{ t("excel.delete") }}</el-button>
      </template>
      <el-table-column type="expand">
      <template #default="scope">
        <div>
          <el-table :data="scope.row.family" >
            <el-table-column label="Name" prop="name" />
            <el-table-column label="State" prop="state" />
            <el-table-column label="City" prop="city" />
            <el-table-column label="Address" prop="address" />
            <el-table-column label="Zip" prop="zip" />
          </el-table>
        </div>
      </template>
    </el-table-column>
    </ProTable>

2、在 tableData1 中每个对象加id值

复制代码
const tableData1 = [
  {
    id: 1,
    family: [
      {
        name: 'Jerry1',
        state: 'California',
        city: 'San Francisco',
        address: '3650 21st St, San Francisco',
        zip: 'CA 94114',
      }
    ],
  },
  {
    id: 2,
    family: [
      {
        name: 'Jerry2',
        state: 'California',
        city: 'San Francisco',
        address: '3650 21st St, San Francisco',
        zip: 'CA 94114',
      }
    ]
  }
]

问题解决

相关推荐
剪刀石头布啊10 分钟前
vue-react为何要虚拟dom
前端
剪刀石头布啊11 分钟前
ahooks常用的一些库,我们使用一下
前端
剪刀石头布啊13 分钟前
从git更新本地提交记录到更新已经推送到远端记录
前端
Flynt2 小时前
axios 被投毒半年后,我把 npm 的"安全防线"实测了一遍:最信任的 SHA512 是安慰剂
前端·npm·node.js
excel3 小时前
Base62 和 Base64 有什么区别?
前端
风骏时光牛马4 小时前
大模型底层架构与AI源码深度剖析
前端
掘金挖土5 小时前
前端手摸手跑路之 AI 应用开发(九)
前端·后端
中文呀7 小时前
三维 GIS 离线缓存实战:逆向 CesiumOfflineCache,并亲手为它补上"自动更新"能力
前端
前进前进前进8 小时前
TRAE 全链路实战:做了一个警示牌一键生成器:纯 Canvas、单文件、零依赖
前端