exportExcelApi(params).then((res) => {
console.log(res);
loading.close();
if(!res.data || res.data.type === 'application/json'){
this.$notify({
title: this.$t("common.error"),
message: this.$t("common.exportError"),
type: 'error'
});
return
}
let head = res.headers['content-disposition'];
let type = res.headers['content-type'];
let fname = '';
if (head) {
fname = head.split(';')[1].split('=')[1];
let reg = new RegExp('"',"g");
let reg2 = new RegExp('\\+', "g");
fname = decodeURI(fname.replace(reg, ""));
fname = fname.replace(reg2, " ");
}
console.log(fname);
var blob = new Blob([res.data], {type: type})
var url = window.URL.createObjectURL(blob);
var aLink = document.createElement("a");
aLink.style.display = "none";
aLink.href = url;
aLink.setAttribute("download", fname);
document.body.appendChild(aLink);
aLink.click();
document.body.removeChild(aLink); //下载完成移除元素
window.URL.revokeObjectURL(url); //释放掉blob对象
}).catch((err) => {
loading.close();
this.$notify({
title: this.$t("common.error"),
message: this.$t("common.exportError"),
type: 'error'
});
return
});
excel blob文件流的导出
最新推荐文章于 2024-04-17 20:24:51 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)