getFormPromise(form) {
return new Promise(resolve => {
form.validate(res => {
resolve(res);
})
})
},
async submitForm(formName,type){ //提交按钮
this.saveLoading = true;
const mustForm = this.$refs.mustRewardRef.$refs.ruleForm; // 表单1
const extraForm = this.$refs.extraRewardRef.$refs.ruleForm; // 表单2
const ruleFormly = this.$refs.ruleFormly; // 表单3
// 使用Promise.all去校验结果
Promise.all([ruleFormly,mustForm, extraForm].map(this.getFormPromise)).then(res => {
const validateResult = res.every(item => !!item);
if (validateResult) {
console.log('表单都校验通过');
} else {
this.saveLoading = false;
console.log('表单未校验通过');
}
})
},
使用 Promise.all 校验多个表单(element-ui)
最新推荐文章于 2024-08-24 02:26:24 发布
本文介绍了一种使用Promise和Promise.all进行多个表单验证的方法,确保所有表单都通过验证后才进行提交操作,提高了表单处理的效率和准确性。
2339





