請求回來的流有可能是亂碼,如圖所示:
處理方法:
第一步:發送請求時:
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">