实现 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)
}
相关推荐
许商15 分钟前
【stm32】【printf】
java·前端·stm32
JIngJaneIL24 分钟前
智慧物业|物业管理|基于SprinBoot+vue的智慧物业管理系统(源码+数据库+文档)
java·前端·数据库·vue.js·spring boot·论文·智慧物业管理系统
爬坑的小白27 分钟前
vue 2.0 路由跳转时新开tab
前端·javascript·vue.js
爬坑的小白28 分钟前
vue x 状态管理
前端·javascript·vue.js
凌览42 分钟前
一键去水印|5 款免费小红书解析工具推荐
前端·javascript·后端
lichong9511 小时前
鸿蒙 web组件开发
前端·typescript
1024小神1 小时前
在html中使用js动态交换两个元素的位置
前端
鹿鹿鹿鹿isNotDefined1 小时前
逐步手写,实现符合 Promise A+ 规范的 Promise
前端·javascript·算法
一千柯橘1 小时前
Electron - IPC 解决主进程和渲染进程之间的通信
前端
申阳1 小时前
Day 16:02. 基于 Tauri 2.0 开发后台管理系统-项目初始化配置
前端·后端·程序员