vue项目,axios请求图片接口,接口返回的是文件流的形式,如何转换成图片?

axios
  .get('/captcha', {
    params: param,
    responseType: 'arraybuffer'
  })
  .then(response => {
    return 'data:image/png;base64,' + btoa(
      new Uint8Array(response.data)
        .reduce((data, byte) => data + String.fromCharCode(byte), '')
    );
  }).then(data => {
    ...
  })

 这样写即可,

如果请求中没有额外的头信息,只需要加img标签src=请求接口地址即可

原文地址:https://www.cnblogs.com/ttjm/p/10394184.html