请求后台得到文件流,下载后台响应的文件流

  		var res=res;//接口响应的数据
  		 var elink = document.createElement('a');
          elink.download = "文件.xls";
          elink.style.display = 'none';
          var blob = new Blob([res],{type: 'application/vnd.ms-excel'});
          elink.href =  window.URL.createObjectURL(blob);
          document.body.appendChild(elink);
          elink.click();
          document.body.removeChild(elink);

当使用axios下载文件乱码,解决方式如下:

 axios({
        method:'get',
        url:url,
        responseType:'arraybuffer'//重点是配置这里
      })
        .then(function(response) {
          //响应结果
        });
    })
发布了76 篇原创文章 · 获赞 9 · 访问量 6万+

猜你喜欢

转载自blog.csdn.net/github_38928905/article/details/94999641