电脑知识|欧美黑人一区二区三区|软件|欧美黑人一级爽快片淫片高清|系统|欧美黑人狂野猛交老妇|数据库|服务器|编程开发|网络运营|知识问答|技术教程文章 - 好吧啦网

您的位置:首頁技術文章
文章詳情頁

vuejs element table 表格添加行,修改,單獨刪除行,批量刪除行操作

瀏覽:88日期:2023-01-05 11:40:27

1.表格動態添加,也可刪除

<template> <div class='TestWord'> <el-button @click='addLine'>添加行數</el-button> <el-button @click='save'>保存</el-button> <el-table :data='tableData' style='width: 100%'> <el-table-column prop='bookname' label='書名'> <template slot-scope='scope'> <el-input v-model='scope.row.bookname' placeholder='書名'></el-input> </template> </el-table-column> <el-table-column prop='bookvolume' label='冊數'> <template slot-scope='scope'> <el-input v-model='scope.row.bookvolume' placeholder='冊數'></el-input> </template> </el-table-column> <el-table-column prop='bookbuyer' label='購買者'> <template slot-scope='scope'><el-input v-model='scope.row.bookbuyer' placeholder='購買者'></el-input> </template> </el-table-column> <el-table-column prop='bookborrower' label='借閱者'> <template slot-scope='scope'> <el-input v-model='scope.row.bookborrower' placeholder='借閱者'></el-input> </template> </el-table-column> <el-table-column prop='bookbuytime' label='購買日期'> <template slot-scope='scope'><el-date-picker v-model='scope.row.bookbuytime' type='date' format='yyyy-MM-dd' value-format='yyyy-MM-dd' placeholder='購買日期'></el-date-picker> </template> </el-table-column> <el-table-column prop='bookbuytime' label='購買日期'> <template slot-scope='scope'><el-button size='mini' type='danger' v-if='!scope.row.editing' icon='el-icon-delete' @click='handleDelete(scope.$index, scope.row)'>刪除</el-button> </template> </el-table-column> </el-table> </div></template>

vuejs 代碼

export default { name:’TestWorld’, data() { return { tableData:[{bookname: ’’,bookbuytime: ’’,bookbuyer: ’’,bookborrower: ’’,bookvolume:’’ }] } }, methods:{ addLine(){ //添加行數 var newValue = { bookname: ’’, bookbuytime: ’’, bookbuyer: ’’, bookborrower: ’’, bookvolume:’’ }; //添加新的行數 this.tableData.push(newValue); }, handleDelete(index){ //刪除行數 this.tableData.splice(index, 1) }, save(){ //這部分應該是保存提交你添加的內容 console.log(JSON.stringify(this.tableData)) } } }

運行圖片

vuejs element table 表格添加行,修改,單獨刪除行,批量刪除行操作

2.編輯表格 (即使input已經修改過,當點擊取消時,內容不會變)

<template> <div class='TestWorld'> <el-button @click='savemodify'>保存</el-button> <el-table :data='modifyData' style='width: 100%'> <el-table-column prop='bookname' label='書名'> <template slot-scope='scope'> <template v-if='scope.row.editing'> <el-input v-model='scope.row.bookname' placeholder='書名'></el-input> </template> <span v-else>{{ scope.row.bookname }}</span> </template> </el-table-column> <el-table-column prop='bookvolume' label='冊數'> <template slot-scope='scope'><template v-if='scope.row.editing'> <el-input v-model='scope.row.bookvolume' placeholder='冊數'></el-input></template><span v-else>{{ scope.row.bookvolume}}</span> </template> </el-table-column> <el-table-column prop='bookbuyer' label='購買者'> <template slot-scope='scope'><template v-if='scope.row.editing'> <el-input v-model='scope.row.bookbuyer' placeholder='購買者'></el-input></template><span v-else>{{scope.row.bookbuyer}}</span> </template> </el-table-column> <el-table-column prop='bookborrower' label='借閱者'> <template slot-scope='scope'><template v-if='scope.row.editing'> <el-input v-model='scope.row.bookborrower' placeholder='借閱者'></el-input></template><span v-else>{{scope.row.bookborrower}}</span> </template> </el-table-column> <el-table-column prop='bookbuytime' label='購買日期'> <template slot-scope='scope'><template v-if='scope.row.editing'> <el-date-picker v-model='scope.row.bookbuytime' type='date' value-format='yyyy-MM-dd' placeholder='購買日期'> </el-date-picker></template> <span v-else>{{scope.row.bookbuytime}}</span> </template> </el-table-column> <el-table-column prop='editing' label='操作'> <template slot-scope='scope'><el-button type='danger' v-if='!scope.row.editing' icon='el-icon-delete' v-model='scope.$index' @click='handleEdit(scope.$index, scope.row)'>編輯</el-button><el-button v-else type='danger' icon='el-icon-delete' v-model='scope.$index' @click='handleCancle(scope.$index, scope.row)'>取消</el-button> </template> </el-table-column> </el-table> </div></template>

vuejs 代碼

export default { name:’TestWorld’, data() { return { modifyData:[], prevValue:{} } }, mounted(){ this.getData() }, methods:{ getData(){ this.$ajax({method: ’get’,url:’../static/json/1.1.1.json’, //<---本地地址//url: ’/api/drummer/8bd17859’, }).then((response)=>{console.log(JSON.stringify(response.data)) let _data = response.data;let datalength = _data.length;for(let i = 0;i < datalength; i++){ this.$set(_data[i], ’editing’, false)}//賦值this.modifyData = _data; }).catch(function(err){ console.log(err) }) }, handleEdit(index,row){ row.editing = true; console.log(index) this.prevValue = JSON.parse(JSON.stringify(row)); }, handleCancle(index,row){ row.editing = false; let prevContent = this.prevValue.bookname; this.$set(row,'bookname',prevContent); }, savemodify(){ console.log(JSON.stringify(this.modifyData)) } } }

本地的1.1.1.JSON數據

[{'bookname':'普通高等教育物聯網工程專業規劃用書:物聯網技術概論','bookbuytime': '2016-05-04','bookbuyer': '李曉月','bookborrower': '王小虎','bookvolume':'1'},{'bookname':'區塊鏈革命:比特幣底層技術如何改變貨幣、商業和世界','bookbuytime': '2016-05-04','bookbuyer': '李曉月','bookborrower': '李小虎','bookvolume':'1'},{'bookname':'大家一起學配色:數學色彩設計全能書','bookbuytime': '2017-12-04','bookbuyer': '張曉月','bookborrower': '王而虎','bookvolume':'1'}]

如果不用get本地數據,vuejs如下

export default { name:’TestWorld’, data() { return { modifyData:[ { bookname: ’普通高等教育物聯網工程專業規劃用書:物聯網技術概論’, bookbuytime: ’2016-05-04’, bookbuyer: ’李曉月’, bookborrower: ’王小虎’, bookvolume: ’1’, editing: false }, { bookname: ’區塊鏈革命:比特幣底層技術如何改變貨幣、商業和世界’, bookbuytime: ’2016-05-04’, bookbuyer: ’李曉月’, bookborrower: ’李小虎’, bookvolume: ’1’, editing: false }, { bookname: ’大家一起學配色:數學色彩設計全能書’, bookbuytime: ’2017-12-04’, bookbuyer: ’張曉月’, bookborrower: ’王而虎’, bookvolume: ’1’, editing: false }], prevValue:{} } }, methods:{ handleEdit(index,row){ //編輯 row.editing = true; console.log(index) this.prevValue = JSON.parse(JSON.stringify(row)); }, handleCancle(index,row){ //取消 row.editing = false; let prevContent = this.prevValue.bookname; this.$set(row,'bookname',prevContent); }, savemodify(){ console.log(JSON.stringify(this.modifyData)) } } }

運行圖

vuejs element table 表格添加行,修改,單獨刪除行,批量刪除行操作

3.批量刪除行數

<template> <div class='TestWorld'> <el-table ref='multipleTable' :data='tableData3' tooltip-effect='dark' @selection-change='handleSelectionChange'> <el-table-column type='selection' width='55'> </el-table-column> <el-table-column label='日期' width='120'><template slot-scope='scope'>{{ scope.row.date }}</template> </el-table-column> <el-table-column prop='name' label='姓名' width='120'> </el-table-column> <el-table-column prop='address' label='地址' show-overflow-tooltip> </el-table-column> </el-table> <div style='margin-top: 20px'> <el-button @click='batchDelete'>批量刪除</el-button> <el-button @click='toggleSelection()'>取消選擇</el-button> </div> </div></template>

vuejs 代碼

export default { name:’TestWorld’, data() { return {tableData3: [ { date: ’2016-05-03’, name: ’王小虎’, address: ’上海市普陀區金沙江路 1518 弄’ }, { date: ’2016-05-02’, name: ’王小虎’, address: ’上海市普陀區金沙江路 1518 弄’ }, { date: ’2016-05-04’, name: ’王小虎’, address: ’上海市普陀區金沙江路 1518 弄’ }, { date: ’2016-05-01’, name: ’王小虎’, address: ’上海市普陀區金沙江路 1518 弄’ }, { date: ’2016-05-08’, name: ’王小虎’, address: ’上海市普陀區金沙江路 1518 弄’ },{ date: ’2016-05-06’, name: ’王小虎’, address: ’上海市普陀區金沙江路 1518 弄’ },{ date: ’2016-05-07’, name: ’王小虎’, address: ’上海市普陀區金沙江路 1518 弄’ }], multipleSelection: [] } }, methods:{ toggleSelection(rows) { if (rows) {rows.forEach(row => {this.$refs.multipleTable.toggleRowSelection(row); }); } else {this.$refs.multipleTable.clearSelection(); } }, batchDelete(){ let multData = this.multipleSelection; let tableData =this.tableData3; let multDataLen = multData.length; let tableDataLen = tableData.length; for(let i = 0; i < multDataLen ;i++){ for(let y=0;y < tableDataLen;y++){ if(JSON.stringify(tableData[y]) == JSON.stringify(multData[i])){ //判斷是否相等,相等就刪除 this.tableData3.splice(y,1) console.log('aa') } } } }, handleSelectionChange(val) { this.multipleSelection = val; } } }

有關驗證的代碼,看上面,持續更新~

以上這篇vuejs element table 表格添加行,修改,單獨刪除行,批量刪除行操作就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Vue
相關文章:
主站蜘蛛池模板: bkzzy在职研究生网 - 在职研究生招生信息咨询平台 | 影像测量仪_三坐标测量机_一键式二次元_全自动影像测量仪-广东妙机精密科技股份有限公司 | 播音主持培训-中影人教育播音主持学苑「官网」-中国艺考界的贵族学校 | 微型气泵-真空-蠕动-水泵-厂家-深圳市品亚科技有限公司 | 广州展览制作|展台制作工厂|展览设计制作|展览展示制作|搭建制作公司 | 首页 - 军军小站|张军博客| 超声波_清洗机_超声波清洗机专业生产厂家-深圳市好顺超声设备有限公司 | 翻斗式矿车|固定式矿车|曲轨侧卸式矿车|梭式矿车|矿车配件-山东卓力矿车生产厂家 | 健康管理师报名入口,2025年健康管理师考试时间信息网-网站首页 塑料造粒机「厂家直销」-莱州鑫瑞迪机械有限公司 | 镀锌方管,无缝方管,伸缩套管,方矩管_山东重鑫致胜金属制品有限公司 | 万师讲师网-优质讲师培训师供应商,讲师认证,找讲师来万师 | 高铝砖-高铝耐火球-高铝耐火砖生产厂家-价格【荣盛耐材】 | lcd条形屏-液晶长条屏-户外广告屏-条形智能显示屏-深圳市条形智能电子有限公司 | 单级/双级旋片式真空泵厂家,2xz旋片真空泵-浙江台州求精真空泵有限公司 | 带式压滤机_污泥压滤机_污泥脱水机_带式过滤机_带式压滤机厂家-河南恒磊环保设备有限公司 | 流程管理|流程管理软件|企业流程管理|微宏科技-AlphaFlow_流程管理系统软件服务商 | 双段式高压鼓风机-雕刻机用真空泵-绍兴天晨机械有限公司 | 防渗膜厂家|养殖防渗膜|水产养殖防渗膜-泰安佳路通工程材料有限公司 | 交通信号灯生产厂家_红绿灯厂家_电子警察监控杆_标志杆厂家-沃霖电子科技 | 激光内雕_led玻璃_发光玻璃_内雕玻璃_导光玻璃-石家庄明晨三维科技有限公司 激光内雕-内雕玻璃-发光玻璃 | 空压机网_《压缩机》杂志| 制冷采购电子商务平台——制冷大市场 | 清水-铝合金-建筑模板厂家-木模板价格-铝模板生产「五棵松」品牌 | 净化板-洁净板-净化板价格-净化板生产厂家-山东鸿星新材料科技股份有限公司 | 深圳品牌设计公司-LOGO设计公司-VI设计公司-未壳创意 | 好物生环保网、环保论坛 - 环保人的学习交流平台 | 不锈钢水箱生产厂家_消防水箱生产厂家-河南联固供水设备有限公司 | SOUNDWELL 编码器|电位器|旋转编码器|可调电位器|编码开关厂家-广东升威电子制品有限公司 | 无线联网门锁|校园联网门锁|学校智能门锁|公租房智能门锁|保障房管理系统-KEENZY中科易安 | 列管冷凝器,刮板蒸发器,外盘管反应釜厂家-无锡曼旺化工设备有限公司 | 非标压力容器_碳钢储罐_不锈钢_搪玻璃反应釜厂家-山东首丰智能环保装备有限公司 | 智能门锁电机_智能门锁离合器_智能门锁电机厂家-温州劲力智能科技有限公司 | 北京普辉律师事务所官网_北京律师24小时免费咨询|法律咨询 | 快速门厂家批发_PVC快速卷帘门_高速门_高速卷帘门-广州万盛门业 快干水泥|桥梁伸缩缝止水胶|伸缩缝装置生产厂家-广东广航交通科技有限公司 | 仿清水混凝土_清水混凝土装修_施工_修饰_保护剂_修补_清水混凝土修复-德州忠岭建筑装饰工程 | 分子蒸馏设备(短程分子蒸馏装置)_上海达丰仪器 | 流变仪-热分析联用仪-热膨胀仪厂家-耐驰科学仪器商贸 | 企业管理培训,企业培训公开课,企业内训课程,企业培训师 - 名课堂企业管理培训网 | 【ph计】|在线ph计|工业ph计|ph计厂家|ph计价格|酸度计生产厂家_武汉吉尔德科技有限公司 | 合肥白癜风医院_[治疗白癜风]哪家好_合肥北大白癜风医院 | 地脚螺栓_材质_标准-永年县德联地脚螺栓厂家 |