赞
踩
一、封装函数
downloadText(data, name) {
const id = "__ETL_DOWNLOAD_BUTTON__";
const blob = new Blob([data]);
const url = URL.createObjectURL(blob);
let a = document.getElementById("#" + id);
if (!a) {
a = document.createElement("a");
a.id = id;
document.body.append(a);
}
a.href = url;
a.download = name;
a.click();
},
二、后台返回文件流
传参、调接口,下载文件
let params = {
fileName: val.fileName,
filePath: val.filePath
};
const res = await DownLoad(params);
const { data, headers } = res;
if (!headers[“content-disposition”]) {
this.$message.error(“导出数据为空”);
return false;
}
const fileNames = headers[“content-disposition”].split(
“fileName=”
);
console.log(fileNames);
const fileName = decodeURI(fileNames[fileNames.length - 1]);
this.downloadText(data, fileName);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。