new Blob vue中使用文件流进行下载

封装方法
function getExel(url, params, index) {+
return new Promise(function(resolve, reject) {
let data = {
method: "GET",
url:url,
headers: {
'token': gettoken("token")
},
responseType: 'arraybuffer'
}
resolve(axios(data));
})
}
注意:responseType应设置为:'arraybuffer'

发送请求($Api已经挂载在了vue对象上,所以可以这么使用)

this.$Api.getExel("/goodsCheckService/v1/planMaterial/export?idList="+idArray)
.then(response => {
let a = document.createElement('a');

//ArrayBuffer 转为 Blob
let blob = new Blob([response.data], {type: "application/vnd.ms-excel"});

let objectUrl = URL.createObjectURL(blob);
a.setAttribute("href",objectUrl);
a.setAttribute("download", '计划单电子表格.xls');
a.click();
});
原文链接:https://blog.csdn.net/qq_37899792/article/details/90748268

posted @   樱桃树下的约定  阅读(101)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
返回顶端
点击右上角即可分享
微信分享提示