后端返回图形验证码
console 打印的结果
此时前端用axios请求如果直接去拿返回值,就会发现…额…乱码了啊(数据流)
前端处理
用原生 转化
getImg() {
var that = this;
var windowUrl = window.URL || window.webkitURL; //处理浏览器兼容性
var xhr = new XMLHttpRequest();
var url = `${
window.API_BASE_URI}/api/v1/mbc/code`; //验证码请求地址
xhr.open("GET", url, true);
xhr.responseType = "blob";
xhr.onload = function() {
if (this.status == 200) {
var blob = this.response;
that.imgCode = windowUrl.createObjectURL(blob);
}
};
xhr.send();
},