element 数组验证
element 数组验证 ================================================ var repairPart = { Name: '', Specs: '', Quantity: '' }; repairForm: [], function goRepairAccountDiag(flag) partArr.forEach((name, index) => { var part = JSON.parse(JSON.stringify(repairPart)); part.Name = name; if (name=="测试针" && socketModel) { part.Specs = socketModel; } part.Quantity = '1'; this.repairForm.push(part); }); ----------------------------------------------------- <el-form :model="repairForm" ref="repairForm" > <el-form :model="item" ref="parts" v-for="(item, index) in repairForm" :key="index" :inline="true" style="width: 100%;"> <el-form-item :label="'耗材'+(index+1)+':'" :key="item.key" label-width="80px" style="width:35%;"> <el-input type="text" v-model="item.Name" readonly style="width: 130px;"></el-input> </el-form-item> <el-form-item prop= "Specs" style="width: 40%;" :rules="[{ required: true, message: '请选择材料规格', trigger: 'change' }]"> <el-select v-model="item.Specs" clearable filterable allow-create style="width: 220px;" placeholder="@UtilConstants.List_Select_Text"> <el-option v-for="model in PartModelList" :key="model.Value" :label="model.Text" :value="model.Value"></el-option> </el-select> </el-form-item> <el-form-item prop="Quantity" :rules="[{ required: true, message: '请输入下架数量', trigger: 'blur' },]"> @*{ min: 1, message: '数字需大于0', trigger: 'blur' }*@ <el-input type="number" v-model.number="item.Quantity" style="width: 90px;"></el-input> </el-form-item> </el-form> </el-form> ------------------------------------------------- function submitRepairForm(formName) { debugger; // 总的页面验证结果标志 var validPass = true; this.$refs[formName].validate((valid) => { debugger; if (valid) { debugger; for (var i=0; i < this.$refs["parts"].length; i++) { this.$refs["parts"][i].validate(isValid => { if (isValid == 0) { validPass = false; return false; } }); } } else { console.log(formName + 'error submit!!'); return false; } if (validPass) { // 通过验证,提交数据 // KeepAccountsOfConsumableMaterial(toolingType,toolingModel,materialName,count) this.$http.post('KeepAccounts', { parts: this.repairForm }, { emulateJSON: true } ).then(function (res) { if (res.data.ReturnResult == '0') { //在wxt记账成功 this.showMessage('repair', 'success', res.data.ReturnMessage); //防止重复记账 this.isAccountDisabled = true; } else { this.showMessage('repair', 'error', res.data.ReturnMessage); } }, function () { this.showMessage('error', '@SEMI.TMS.Resources.StringResource.Sys_ExeFail'); }); } }); } ----------------------------- { pattern: /^[\u4E00-\u9FA5]+$/, message: '用户名只能为中文', trigger: 'blur' } { validator: Verify.validatePassword, trigger: 'blur' } { min: 1, max: 100, message: '长度在 1 到 100 个字符', trigger: 'blur' } <div v-for="(item, index) in $store.getters.syncArchive.form" :key="index"> <el-form-item label="类型" :prop="'form.' + index + '.chartType'" :rules="{ required: true, message: '请选择表类型', trigger: 'blur' }"> <el-select v-model="item.chartType" v-for="option in options"> <el-option :key="option.option" :value="option.value" :label="option.label"/> </el-select> </el-form-item> </div>