多个表单如何同时验证
最近公司的项目会有大量的表单需要输入很多信息。 比如下面的表单: 我知道的有两种方法: 第一种方法是通过promise.all(),通过promise进行同步验证。代码示例度娘有很多。 我使用的是第二种方法,代码如下: 1 addBaseInfo(){ 2 that.$refs['store'].validate((valid) => { //第一个表单ref="store” 5 if (valid) { 6 this.titleFormValid = true //如果通过,加个true相当于开关判断 7 } 8 }); 9 if(this.store.type==1){ 10 that.$refs['school'].validate((valid) => { //第二个表单ref='school' 11 if(valid){ 12 that.customFormValid = true //同上 13 } 14 }); 15 }else if(this.store.type==3){ 16 that.$refs['company'].validate((valid) => { 17 if(valid){ 18 that.customFormValid = true 19 } 20 }); 21 }else{ 22 that.$refs['community']