el-upload before-upload校验上传的图片尺寸
时间: 2023-09-06 21:13:00 浏览: 233
【JavaScript源代码】vue el-upload上传文件的示例代码.docx
el-upload的before-upload校验可以用于检验上传的图片尺寸。在before-upload钩子内,可以通过获取上传的文件对象,使用相关方法来获取图片的宽度和高度。可以使用JavaScript的Image对象来加载图片,并获取其宽度和高度。然后可以与预设的尺寸进行比较,如果不符合要求,可以返回false或者返回一个被reject的Promise来阻止上传事件的发生。这样就可以校验上传的图片尺寸了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [element-ui 使用el-upload , before-upload函数不好使](https://blog.csdn.net/qq_38998250/article/details/121075056)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
- *2* [el-upload自定义上传http-request,校验文件、图片大小、宽高,有效阻止上传事件](https://blog.csdn.net/doocaa_/article/details/120978892)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文