前端imageBuffer设置图片src(后端返回二进制流图片)
参考地址1:前端imageBuffer设置图片src(后端到前端直传buffer)
参考地址2:axios根据流生成图片
本质为buffer转base64
1 // 获取项目截图 2 getItemPic() { 3 this.$http({ 4 url: this.$http.adornUrl('/web/showimgFile'), 5 method: 'get', 6 responseType: "arraybuffer", // 注意:responseType必须是arrayBuffer,json是不行的 7 params: this.$http.adornParams({ 8 'url' : this.imgId, 9 }) 10 }).then(({ data }) => { 11 let bytes = new Uint8Array(data); 12 let storeData = ""; 13 let len = bytes.byteLength; 14 for (let i = 0; i < len; i++) { 15 storeData += String.fromCharCode(bytes[i]); 16 } 17 this.imgUrl = "data:image/png;base64," + window.btoa(storeData); 18 }); 19 }