说明
vue axios 后端接口返回一个流文件图片,前端base64解析直接展示
代码
getImg(filePath) {
this.$http.get('/img', {
responseType: 'arraybuffer'
}).then(response => {
return 'data:image/png;base64,' + btoa(
new Uint8Array(response.data)
.reduce((data, byte) => data + String.fromCharCode(byte), ''))
}).then(data => {
// console.log(data)
})
}
使用如下
