Axios处理图片文件流
axios.get(url, {
responseType: 'arraybuffer'
}).then(res => {
let base64 = btoa(new Uint8Array(res.data).reduce((data, byte) => data + String.fromCharCode(byte), ''));
return 'data:image/png;base64,' + base64;
});
然后将return
的字符串赋值到img
标签的src
属性中即可
dd