【发布时间】:2020-01-10 07:06:14
【问题描述】:
我的任务是创建和上传图像文件,但我遇到了 blob 和 base64 项目的问题,Blob URL 按预期工作,但是当我尝试使用 FileReader 时,它显示项目正忙于读取 blob。我还尝试删除 URL 的代码文件以保留文件阅读器代码,但仍然存在相同的问题。以及每次创建base64后如何停止它时如何调用onload。或者是否也可以将 blob URL 转换为 base64
uploadImageChange(e){
const file = e.target.files[0];
this.showImageModalErrorMessage = false;
let fileReader = new FileReader();
fileReader.onload = function(fileLoad){
console.log(fileReader.readAsDataURL(file));
}
if(file.size < 2000){
this.imageSelectedUrl = URL.createObjectURL(file);
this.showImageSaveContent = true;
this.modalSecondInstruction = true;
}else{
this.imageModalErrorMessage = "The image you chose is bigger than 2 MB. Kindly upload a smaller-sized photo."
this.showImageModalErrorMessage = true;
}
},
【问题讨论】:
-
您在 console.log() 中拼错了控制台。也许它会挂在上面?
-
感谢您的纠正,但没有:(
标签: javascript vue.js base64 filereader