主要用于获取验证码图片,因为转码看了好久
//responseType值必为arraybuffer,否则不生效
this.$http.post('/passengerTraffic-admin/captcha/getKaptchaImage', params, { responseType: 'arraybuffer' }).then(res => {
console.log(res);
this.url =
'data:image/png;base64,' + btoa(new Uint8Array(res.data).reduce((data, byte) => data + String.fromCharCode(byte), ''));
});
axios 文档对responseType 的说明
responseType
表示服务器响应的数据类型,可以是 ‘arraybuffer’, ‘blob’, ‘document’, ‘json’, ‘text’, ‘stream’
默认的 responseType: ‘json’,