問題描述:
請求后端接口,返回驗證碼圖片亂碼。
根據亂字符+JFIF標記,確定是個JPEG文件的二進制流,而不是base64。
解決方法:
updateCode() { axios.get('ApiUrl', { responseType: 'arraybuffer' }).then((res) => { this.formData.imgUrl = `data: image/jpeg;base64,${btoa(new Uint8Array(res.data).reduce((data, byte) => data + String.fromCharCode(byte), ''))}`; });