【form表单校验】使用el-form表单校验数组时,change和trigger无法触发校验的解决方案
<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('');
});
}
}
}
}