技术框架:vue + antd-vue
代码:
<a-upload
name="file"
:multiple="true"
:showUploadList="false"
:customRequest="customRequest"
:max-count="maxCount"
accept=".jpg,.jpeg,.png,.gif"
:before-upload="beforeUpload">
<a-button>上传图片</a-button>
</a-upload>
const beforeUpload = (file, fileList) => {
if (file.size > 2097152) {//2M 1024*1024*2
message.error('图片大小不能超过2M');
return false
}
let img = new Image();
let url = window.URL || window.webkitURL;
img.src = url.createObjectURL(file)
img.onload = () => {
if (img.height < 100 || img.width < 100) {
message.error('图片尺寸不能小于100*100');
return false
}
}
};