先说axios请求里一定要加 responseType:'arraybuffer'
第一种(如果是web端的推荐使用这个,因为btoa)
const img = 'data:image/png;base64,' + btoa(new Uint8Array(data).reduce((data, byte) =>
data + String.fromCharCode(byte), ''));
第二种(异步不是很推荐)
先将文件流转成blob
let blob = new Blob([data], { type: 'image/png'})
let a = new FileReader();
a.onload = function(e) {
const img = e.target.result;
}
a.readAsDataURL(blob);