多个表单同时验证
项目中遇到这样的多个表单同时提交,内容太多,分成两个form表单,一个是basicForm,一个是advanceForm,点击确定按钮时同时验证,验证通过提交表单,有一个不通过则不提交,代码是这样写的
addData() {
try {
Promise.all([
this.$refs.refName.$refs.ruleForm1.elForm.validate(),
this.$refs.refName.$refs.ruleForm2.elForm.validate()
]).then((res) => {
console.log('效验通过')
})
} catch (error) {
return
}
},
使用的是promisea.all
获取子组件的组件
his.$refs.refName.$refs.ruleForm1.elForm