实现 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)
}
相关推荐
smxgn5 分钟前
spring-boot-starter和spring-boot-starter-web的关联
前端
王中阳Go13 分钟前
2026年,前端这个岗位可能真的要消失了,但另一个正在崛起
前端
wing9822 分钟前
Vue3 接入 Google 登录:极简教程
前端·vue.js·google
weixin1997010801627 分钟前
货铺头商品详情页前端性能优化实战
java·前端·python
new code Boy1 小时前
NestJS、Nuxt.js 和 Next.js
前端·后端
进击切图仔1 小时前
执行 shell 脚本 5 种方式对比
前端·chrome
局i1 小时前
React 简单地图组件封装:基于高德地图 API 的实践(附源码)
前端·javascript·react.js
执行部之龙2 小时前
AI对话平台核心技术解析
前端
yuki_uix2 小时前
防抖(Debounce):从用户体验到手写实现
前端·javascript
HelloReader2 小时前
Flutter 进阶 UI搭建 iOS 风格通讯录应用(十一)
前端