如果给出了条件,我创建了一个停止其父级的函数:
handleUserSubmit () {
this.userForm.options.hasFormSubmitted = true
if (!this.userForm.options.isFormValid) return
},
handleUpdateUser () {
const fields = this.userForm.schema
this.userInput.buildId = this.user.objectId
this.handleUserSubmit()
// rest of code
}
然而,无论条件如何,其余代码都会运行。我做错了什么?
答案 0 :(得分:1)
将条件返回移动到需要从中返回的函数:
handleUserSubmit () {
this.userForm.options.hasFormSubmitted = true
return !this.userForm.options.isFormValid;
},
handleUpdateUser () {
const fields = this.userForm.schema
this.userInput.buildId = this.user.objectId
if(this.handleUserSubmit()) return;
// rest of code
}