Vue拿到二进制流图片转为正常图片并显示

axios({
method: 'get',
url,
responseType: 'arraybuffer' // 最为关键
})
.then(function (response) {
that.src = 'data:image/jpeg;base64,' + that.arrayBufferToBase64(response.data)
})

arrayBufferToBase64 (buffer) {
var binary = ''
var bytes = new Uint8Array(buffer)
var len = bytes.byteLength
for (var i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i])
}
return window.btoa(binary)
},

验证码
原文作者:https://blog.csdn.net/qq_37241934/article/details/108639364

你可能感兴趣的:(Vue拿到二进制流图片转为正常图片并显示)