admin管理员组

文章数量:1794759

Vue两个方法用同一个函数(这个函数里有return)时应该怎么用

Vue两个方法用同一个函数(这个函数里有return)时应该怎么用

//关于标题上的问题,可能用复杂了代码有点多,就是设置一个开关的方法。 再data里面为true,return的语句里面把它设置为false,再你使用的方法里判断这个开关如果为false那么就return不往下面执行 代码: 公用的方法里

if (this.SXarray.findIndex(i => i.identifier === this.structForm.flag) !== -1 &&this.SxEnter == "添加") { **this.pdFlag = false** return this.$message.error("已经存在,请重新输入"); } if (this.SXarray.findIndex(i => i.name === this.structForm.name) !== -1 &&this.SxEnter == "添加") { **this.pdFlag = false** return this.$message.error("名称已经存在,请重新输入"); }

你用到上面函数的方法里

oneSave(onesx){ this.$refs[onesx].validate(valid => { if (valid) { this.pdFlag = true this.initSubmit() console.log(this.pdFlag); if(this.pdFlag!=false){ this.AddCS() } this.Struct_dialogFormVisible = true; } else { return false; } }); },

其中遇到点问题:是做添加并继续的功能,第一次添加了这些值在一个数组里已经有了这个值,这个弹窗不会关闭所以上面的值还是保留状态,如果用户再点击这值没有清空就会报return里面的错误,所以一直为false就不会为true,所以再调用提示方法的上面把这个标识设置为true,点击保存时为true,如果走到你调用的方法 this.initSubmit()为false那么就return不往下执行了。 完美解决

本文标签: 函数该怎么时应两个方法