小工具知识网

当前位置: 首页 > 行业知识 > Vue+element UI 可编辑表格

行业知识

Vue+element UI 可编辑表格

2026-11-29 16:51:17 来源:互联网转载

前���开发过程中,我们都会尽量避免多层弹窗的嵌套,最多两层弹窗嵌套。这么做的原因是为了方便管理代码和防止多层嵌套弹窗造成bug。但是有时候,内层的弹窗可能展示了一个表格,并且需要操作表格中的数据,这个时候我们只能自己DIY一个表格,取代弹窗处理的方法。

1,实现效果和逻辑

效果:表格展示数据,并且表格可以编辑数据(增、删、改)。

逻辑:实现可编辑表格的主要思想:使用table创立一个表格,正常展示数据,需要操作某一行数据时,根据行数据的ID作为标志,将该行HTML换成编辑框或者其他form组件。

2,效果图

 2,代码

HTML:

序号 节点名称 验收人 人员信息 方式 操作
{{ index+1 }} {{ item.name }} 全部人员 指定人员 {{ item.accepterName }} 全部 会签 或签 {{ index+1 }} 全部人员 指定人员 全部 会签 或签
添加验收节点

JavaScript:

    export default {        data() {            return {                checkedList: [], // 验收节点列表                customCurrentId: '', // 验收节点编辑时节点ID                customCurrentObj: {}, // 验收节点编辑时节点数据            }        },        methods: {            // 新增验收节点            addOtherForm(){              let num = new Date().getTime()              this.checkedList.push({name:'', type:0, accepter:'', accepterName:'', accepterList: [], way:1, id: 'addNew'+num })              this.customCurrentId = 'addNew'+num              this.customEditHandle(this.checkedList[this.checkedList.length-1])            },            // 删除验收节点            customDeleteHandle(item) {              this.checkedList = this.checkedList.filter((ele) => {                return ele.id !== item.id              })              // 至少保留一条验收节点              if(this.checkedList && this.checkedList.length === 0) {                this.$message({                  message: '请至少保留一条验收节点!',                  type: 'error',                  duration: 1000,                  onClose: () => {                    this.addOtherForm()                  }                })              }            },            // 编辑验收节点            customEditHandle(data){                this.customCurrentId = data.id                try {                  this.customCurrentObj = JSON.parse(JSON.stringify(data))                } catch (error) {                          }            },            // 修改确认验收节点            customCheckOK(data){              // 验收节点,填写完整的校验              let columsEntityFlag = false              let checkedPersonFlag = false              if(this.customCurrentObj.type === 0) {                checkedPersonFlag = false              }else if(this.customCurrentObj.type === 1 && this.customCurrentObj.accepter === '') {                checkedPersonFlag = true              }              if(!this.customCurrentObj.name || checkedPersonFlag) {                columsEntityFlag = true              }              if(columsEntityFlag) {                this.$message({                  message: '请将您添加的验收节点填写完整!',                  type: 'error',                })                return false              }              this.checkedList.forEach((item, index) => {                if(item.id === this.customCurrentId) {                  try {                    this.checkedList[index] = JSON.parse(JSON.stringify(this.customCurrentObj))                  } catch (error) {                              }                }              })              this.$message({                message: '修改成功',                type: 'success',                duration: 1000,                onClose: () => {                  this.customCurrentId = ''                }              });            },            // 取消修改验收节点            customCheckcancel(){              let columsEntityFlag = false              let checkedPersonFlag = false              if(this.customCurrentObj.type === 0) {                checkedPersonFlag = false              }else if(this.customCurrentObj.type === 1 && this.customCurrentObj.accepter === '') {                checkedPersonFlag = true              }              if(!this.customCurrentObj.name || checkedPersonFlag) {                columsEntityFlag = true              }              if(columsEntityFlag) {                this.$message({                  message: '请将验收节点填写完整!',                  type: 'error',                })                return false              }                this.customCurrentId = ''            },        }    }

可编辑表格功能就记录到此了,有需要的小伙伴拿去用,希望对你们有所帮助。

这个方法实现可能比较low,谁有更好的方法请多多指导。

拜了个拜,迪迦。。。

上一篇:怎么去掉ip定位服务器?

下一篇:怎么下载海尔云服务器?