vue axios请求图片流文件前端页面显示处理方法


请求回来的流有可能是乱码,如图所示:

处理方法:

第一步:发送请求时:

let url = `/frm/v1/api/images/${options.id}`;
    axios.get(url,{responseType: 'arraybuffer'}).then(function(data){
      success(data);
    }).catch(function(err){
      error(err)
    });

第二步:处理返回的数据结果

pic.imgUrl = 'data:image/png;base64,' + btoa(new Uint8Array(data.data).reduce((data, byte) => data + String.fromCharCode(byte), ''))

  在img标签中:

<img v-if="selectedLogoPicture" ref="selectlogoPictureImg" :src="selectedLogoPicture.imgUrl" class="logoImg">

  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM