document.write("");

el-form 自定义验证规则,手动触发某项验证

1. ui

<el-form ref="xXXForm" :rules="XXXFormRules" >
	 <el-form-item label="图片" prop="xxx">
	 </el-form-item>
</el-form>

2. 变量初始化

export default {
  data() {
  return {
		......
		XXXFormRules: {
			......
			xxx: [
				{
					required: false,
					validator: isEmptyRule,
					trigger: 'change'
				}
			],
			......
		},
		......
	}
}

 

验证方法:

 

	const isEmptyRule = (rule, value, callback) => {
		if (value == null || value == "") {
			callback(new Error('请上传图片')) // 一定要写 callBack()
		} else {
			callback()
		}
	};

 

  

3. 手动触发

this.$refs.xXXForm.validateField('xxx');

  

posted @ 2023-07-19 17:16  人间春风意  阅读(1150)  评论(0编辑  收藏  举报