定义函数:
export function transformArrayBufferToBase64( 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 );
}
应用示例:
getPosterQR(obj).then(res => {
console.log(res)
that.erweima = ‘data:image/png;base64,’ + transformArrayBufferToBase64(res)
})