axios的上传下载文件


一 后台返回文件流 的下载,即导出

图片

axios加上responseType:"blob" 取到的就是二进制格式
var blob=new Blob([res.data],{type:"imageType"})

再转连接
var img=(window.URL||window.webkitURL).createObjectURL(blob);
param.image=img;

文件

 axios加上responseType: "arraybuffer" 不是直接读取,是通过视图来读取
 let blob = new Blob([content], {type:"application/zip"}) //zip
 let blob = new Blob([response.data], {type: "application/vnd.ms-excel"});//excel

二 上传

包装成formdata上传

var file = e.target.files[0];
var fd = new FormData();
fd.append("file", file);
element中el-upload中有反参,用formdata包装起来

参考:https://blog.csdn.net/yh95926/article/details/88802455

vue