情景:
如图该请求返回一张图片,我该如何显示在页面上呢?
代码如下:
transformArrayBufferToBase64 (buffer) {
var binary = '';
var bytes = new Uint8Array(buffer);
for (var len = bytes.byteLength, i = 0; i < len; i++) {
binary += String.fromCharCode(bytes[i]);
}
return window.btoa(binary);
}
componentDidMount() {
// ...
this.getSetCodeImg();
}
getSetCodeImg = () => {
timerId = setTimeout(this.getSetCodeImg, 1000 *10 * 60 *5);
axios.get('http://120.77.204.211:9091/api/getCodeImg',{responseType: 'arraybuffer'}).then(res => {
var img = document.create