3.0.3
win7,chrome63.0.3239.84
https://codepen.io/LynnHg/pen/YYZdRV
handleBeforeUpload(file) {
const sizeOk = file.size < 1024 * 300;
const typeOk =
file.type === 'image/jpeg' ||
file.type === 'image/png' ||
file.type === 'image/bmp' ||
file.type === 'image/gif';
if (!typeOk) {
message.error('照片格式有误!');
} else {
if (!sizeOk) {
message.error('照片大小超过300K!');
}
}
return sizeOk && typeOk;
}
当上传错误格式的照片,提示格式错误,但不显示任何效果
当上传错误格式的照片,提示格式错误,但界面上显示了"文件上传中"
用英语写您的问题/评论会更好,这样更多的人可以理解您。
这意味着更多的人可以帮助您或从您的问题/评论中受益。
参见: https :
这是因为onChange
的回调方法有问题,不能这样写
我认为这是一个问题,当beforeUpload
false时,回调onChange
file
对象应该给出正确的status
。
如果使用Promise,拒绝将不会触发onChange
,但返回false会!
if (!typeOk) {
message.error('照片格式有误!');
return false
}
if (!sizeOk) {
message.error('照片大小超过300K!');
return false
}
return true;
#8020重复
beforeUpload(文件){
const maxFileSize = 2;
const isLtMax = file.size / 1024/1024 <maxFileSize;
return new Promise((resolve, reject) => {
if(!isLtMax) {
reject(file);
} else {
resolve(file);
}
});
};
这样可以防止错误文件添加到fileList中。
最有用的评论
beforeUpload(文件){
const maxFileSize = 2;
const isLtMax = file.size / 1024/1024 <maxFileSize;
};
这样可以防止错误文件添加到fileList中。