修改获取base64代码错误

This commit is contained in:
结发受长生 2020-01-30 18:00:05 +08:00
parent 887b74dbcf
commit da6a1e78ec
2 changed files with 3 additions and 3 deletions

View File

@ -33,4 +33,4 @@
"nunjucks": "^3.2.0",
"optimist": "^0.6.1"
}
}
}

View File

@ -26,11 +26,11 @@ fileInput.addEventListener('change', function() {
var file = fileInput.files[0];
var reader = new FileReader();
var fileBase64 = null;
reader.onload = function() {
reader.onload = function(e) {
fileBase64 = e.target.result; //base64编码
}
reader.readAsDataURL(file);
}
})
```
这里获取到的`fileBase64`就是文件的base64编码
如果这个文件是一个图片 , 我们当然可以借助它来实现所选图片的预览