实现 Table 的增加和删除,不依赖后端数据回显

需求

  • 删除前

  • 删除后

分析

首先写一个 Table

javascript 复制代码
 <a-card style="width:100%">
     <template#extra>
         <a-button type="text" @click="addSelectItem" style="margin-right: 5px">
             添加
         </a-button>
         <a-button type="text" @click="packUpOrCloseVisible = !packUpOrCloseVisible">{{
packUpOrCloseVisible ? "收起" : "展开" }}
         </a-button>
     </template>
     <a-table v-if="packUpOrCloseVisible" :data="editForm.partyMemberList" :bordered="false"
         :pagination="false" style="width:100%">
         <template #columns>
             <a-table-column title="姓名" align="center">
                 <template #cell="{ record }">
                     <el-input v-model="record.memberName" placeholder="请选择人员" />
                 </template>
             </a-table-column>
             <a-table-column title="电话" align="center">
                 <template #cell="{ record }">
                     {{ record.fundsReportId || '暂无' }}
                 </template>
             </a-table-column>
             <a-table-column title="操作" align="center">
                 <template #cell="{ record, rowIndex }">
                     <a-button type="text" @click="deleteSelectItem(record, rowIndex)"
                         status="danger">
                         <template #icon><icon-delete /></template>
                         删除
                     </a-button>
                 </template>
             </a-table-column>
         </template>
     </a-table>
 </a-card>

我们可以对数组进行操作,首先是增加操作

javascript 复制代码
function addSelectItem() {
    editForm.value.partyMemberList.push({
        memberName: '',
        phone: ''
    })
}

删除指定元素

javascript 复制代码
// 参会人员删除
function deleteSelectItem(data, index) {
    console.log(data, index)
    editForm.value.partyMemberList.splice(index, 1)
}
相关推荐
@atweiwei3 小时前
LangChainRust 0.33.0 发布:让 Agent 应用更容易运行、观察和评测
服务器·前端·javascript
yuki蜜语4 小时前
「阴升阳降」不符合物理常识?我用一台热虹吸做了个可拆解的 3D 模型
前端·计算机视觉·前端工程化
ZJPRENO4 小时前
一个被身份证认证逼出来的开源项目:AI 辅助开发实战
前端
GoodStudyAndDayDayUp4 小时前
请求前端页面&traefik流程
前端
CV-deeplearning11 小时前
Chrome DevTools实战
前端·agent·chrome devtools·mcp
xurileidian11 小时前
第 30 篇 · 边玩边学Python · 猜数字小游戏 把判断循环异常串起来
前端·python·算法
前端精髓12 小时前
三种方式实现 Agent 工具调用:OpenAI、LangChain 与 LangGraph
前端·数据库·langchain
国科安芯12 小时前
光链路捕获的那一刻:商业激光通信终端捕获跟踪伺服与探测前端的低噪声供电
前端·网络·卫星·电源芯片·抗辐照芯片·在轨
一铭1119912 小时前
微信小程序可视化搭建实战:模板、组件与发布验收
前端·低代码·微信小程序·小程序·页面设计·可视化搭建·发布验收
LabVIEW开发13 小时前
LabVIEW 2025 新特性盘点:这几个改进,值得你认真看一遍
前端·labview