后台返回图形验证码 前端如何处理

后端返回图形验证码

在这里插入图片描述

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();
    },

猜你喜欢

转载自blog.csdn.net/IT_iosers/article/details/120668037