主要用于获取验证码图片,因为转码看了好久
//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’,
最后
以上就是文艺小蜜蜂最近收集整理的关于axios接收base64文件流,转换为图片的全部内容,更多相关axios接收base64文件流内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复