1. 先封一个校验方法:
方法代码:
formRulesValidate(fName){ return new Promise((resolve)=>{ this.$refs[fName].validate(valid=>{ if(valid) resolve(valid); }); }); },
2. 保存,确定按钮点击得时候触发:
saveVal(AgencyForm) { let formRulesOneRes = this.formRulesValidate('companyData'); let formRulesTwoRes = this.formRulesValidate('userAgendata'); Promise.all([formRulesOneRes,formRulesTwoRes]).then(()=>{ this.$emit("saveConstData",this.AgencyForm); //// 这里面写自己需要得 }).catch(() => { console.log('err') this.$message.error('请完善信息!') }) },
清除form:
clearStyle() { this.$refs.companyData.resetFields(); this.$refs.userAgendata.resetFields(); },标签:el,form,refs,校验,valid,formRulesValidate From: https://www.cnblogs.com/zxhh/p/17982526