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',
      }
    ]
  }
]

问题解决

相关推荐
IT_陈寒1 小时前
JavaScript项目实战经验分享
前端·人工智能·后端
用户47949283569152 小时前
6w star,GitHub 趋势第一的 Ponytail,这个agent插件到底在火什么
前端·后端
薛定喵的谔3 小时前
我开源了一个精致的 Next.js 博客模板:Skyplume
前端·前端框架·next.js
张龙6874 小时前
构建生产级 AI Agent:工具调用与记忆架构实战指南
前端
kyriewen5 小时前
2026 年了,还在用 Node.js?Bun 迁移实战:20 分钟搞定,附踩坑记录
前端·javascript·node.js
青山Coding7 小时前
Cesium应用(八):物体运动的实现思路
前端·cesium
用户41659673693557 小时前
Android WebView 加载 file:// 离线页面调试教程
android·前端
Asmewill7 小时前
curl命令学习笔记一
前端
我是一只快乐的小螃蟹7 小时前
1.2 ArrayList 源码解析
前端
星栈7 小时前
我用 Rust + Dioxus 做了个全栈跨平台笔记应用:再把新建、编辑和交付补上
前端·rust·前端框架