Vue下载流文件
后台返回的数据格式前端处理$({method: "get",url: "/dafw/cljsdc",params: data,responseType: "blob" 设置接收数据的类型}).then((res)=>{const fileName = res.headers["content-disposition"].split("=")[1];con...
·
后台返回的数据格式
前端处理
$({
method: "get",
url: "/dafw/cljsdc",
params: data,
responseType: "blob" 设置接收数据的类型
}).then((res)=>{
const fileName = res.headers["content-disposition"].split("=")[1];
const _res = res.data;
let blob = new Blob([_res]);
let downloadElement = document.createElement("a");
let href = window.URL.createObjectURL(blob); //创建下载的链接
downloadElement.href = href;
downloadElement.download = fileName; //下载后文件名
document.body.appendChild(downloadElement);
downloadElement.click(); //点击下载
document.body.removeChild(downloadElement); //下载完成移除元素
window.URL.revokeObjectURL(href); //释放掉blob对象
})
更多推荐
已为社区贡献4条内容
所有评论(0)