js处理后端返回的图片二进制流

vue axios async/await FileReader

例:<img  :src="imgSrc"><button @click="handleBtn">

getUrl (apiUrl, params) {
  return axios({
    url: apiUrl,  
    method: 'get',
    responseType: 'blob',
    params
  })
},
async handleBtn () {
  let that = this
  let params = {}
  let data = await this.getUrl("/getQRcode", params)
  let blob = data.data;
  let reader = new FileReader();
  reader.readAsDataURL(blob);
  reader.onload = function (e) {
    let url = e.target.result;
    that.imgSrc = url
    that.flag = true
  }
}
posted @ 2021-08-03 09:56  kimsaerono  阅读(975)  评论(0编辑  收藏  举报