vue element ui在form表单中校验upload组件是否上传

思路:给 el-form-item 加上ref属性,在上传成功钩子函数中取消该项的表单校验

<el-form-item label="附件:" prop="file_id" ref="file_Rule">  //给该项加ref
  <el-upload
	  class="upload-demo"
	  action="https://jsonplaceholder.typicode.com/posts/"
	  :on-success="handleSuccess"
	  :file-list="fileList">
	  <el-button size="small" type="primary">点击上传</el-button>
	  <div slot="tip" class="el-upload__tip">只能上传jpg/png文件,且不超过500kb</div>
	</el-upload>
</el-form-item>

handleSuccess(res, file) {  //上传成功钩子
 	this.$refs.file_Rule.clearValidate();  //取消该项校验
},
ps:相反开启校验使用 this.$refs.file_Rule.validate();

你可能感兴趣的:(elementui)