前端處理後臺返回的亂碼圖片

問題描述:ios

  請求後臺接口,返回以下圖的亂碼。axios

根據全場亂字符+JFIF標記,肯定是個JPEG文件的二進制流,而不是base64。api

解決方法:this

  

1 this.$axios.get('api',{responseType: 'arraybuffer'}) 2  .then(res=>{ 3     this.formData.imgUrl =  'data:image/png;base64,' + btoa( 4     new Uint8Array(res.data).reduce((data, byte) => data + String.fromCharCode(byte), '')) 5 })

注意:*****設置請求數據類型:responseType:'arraybuffer'******spa

相關文章
相關標籤/搜索