【form表单校验】使用el-form表单校验数组时,change和trigger无法触发校验的解决方案

时间:2025-03-28 16:17:14
<el-form-item ref="fileitem" label-width="0" prop="fileSaves"> {{formDData.fileSaves}} </el-form-item> data() { const isHasFile = (rule, value, callback) => { if (!value || value.length < 1) { callback(new Error('请上传附件')); } else { callback(); } }; return { rules: { fileSaves: [{ required: true, trigger: ['blur', 'change'], validator: isHasFile }] }, } } watch: { '': { handler (newVal, oldVal) { if (!newVal || !newVal.length) { this.$nextTick(() => { this.$refs.fileitem.$emit(''); }); } } } }