多个表单同时校验

目前公司的商家后台项目,在新增商品的时候,分成了多个模块,提交的表单的数据也是有多个对象组成,假设现在有baseInfoForm,skuInfoForm,freightForm,点击确定同时校验,验证通过则提交,一个不通过则不提交,使用promise.all

async saveInfo() {
    try {
        await Promise.all([
            this.$refs.baseInfoForm.validate(),
            this.$refs.skuInfoForm.validate(),
            this.$refs.freightForm.validate()
        ]);
    } catch (error) {
        return;
    }
}

 

Logo

前往低代码交流专区

更多推荐