问题描述:
请求后端接口,返回验证码图片乱码。
根据乱字符+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), ''))}`; });