AI智能
改变未来

elementui上传图片校验

<el-form-itemref=\"image\"label=\"商品主图\"prop=\"first_image_url\"><div class=\"picture-card\"><el-upload:multiple=\"false\":data=\"uploadMainImageData\":before-upload=\"beforeUploadMainImage\":action=\"upload\":show-file-list=\"false\":on-success=\"uploadMainImageSuccess\"class=\"avatar-uploader\"accept=\".jpg, .jpeg, .png, .gif, .JPG, .JPEG, .PNG, .GIF\"list-type=\"picture-card\"><imgv-if=\"basicFormData.first_image_url\":src=\"basicFormData.first_image_url\"class=\"avatar-upload-image\"><iv-elseclass=\"el-icon-plus avatar-uploader-icon\"/></el-upload></div></el-form-item>//自定义正则var valiIcon = (rule, value, callback) => {// 图片验证if (!this.basicFormData.first_image_url) {callback(new Error(\"请上传商品主图\"));} else {callback();}//rulesfirst_image_url: [{ required: true, validator: valiIcon }]//上传成功uploadMainImageSuccess(res) {this.$refs.image.clearValidate();},//删除成功handleRemove(file) {this.basicFormData.first_image_url=\'\'this.$refs.image.validate();}
赞(0) 打赏
未经允许不得转载:爱站程序员基地 » elementui上传图片校验