实现 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)
}
相关推荐
fanruitian1 小时前
uniapp android开发 测试板本与发行版本
前端·javascript·uni-app
rayufo1 小时前
【工具】列出指定文件夹下所有的目录和文件
开发语言·前端·python
RANCE_atttackkk1 小时前
[Java]实现使用邮箱找回密码的功能
java·开发语言·前端·spring boot·intellij-idea·idea
2501_944525543 小时前
Flutter for OpenHarmony 个人理财管理App实战 - 支出分析页面
android·开发语言·前端·javascript·flutter
李白你好4 小时前
Burp Suite插件用于自动检测Web应用程序中的未授权访问漏洞
前端
刘一说5 小时前
Vue 组件不必要的重新渲染问题解析:为什么子组件总在“无故”刷新?
前端·javascript·vue.js
徐同保6 小时前
React useRef 完全指南:在异步回调中访问最新的 props/state引言
前端·javascript·react.js
刘一说6 小时前
Vue 导航守卫未生效问题解析:为什么路由守卫不执行或逻辑失效?
前端·javascript·vue.js
一周七喜h7 小时前
在Vue3和TypeScripts中使用pinia
前端·javascript·vue.js
weixin_395448917 小时前
main.c_cursor_0202
前端·网络·算法