download = (url, params) => {
let filename;
window.fetch(url, {
method: 'POST',
body: JSON.stringify(params),
"Access-Control-Allow-Origin" : "*",
"Access-Control-Allow-Credentials" : true,
header: {
'Content-Type': 'application/json;charset=UTF-8'
}
}).then(function(response) {
// 获取文件名
response.headers.forEach((val, key) => {
if(key === 'content-disposition'){
filename = val.split(";")[1].split("filename=")[1];
}
});
return response.blob();
}).then(function(blob) {
const link = document.createElement('a');
link.style.display = 'none';
let URL = window.URL || window.webkitURL;
link.href = URL.createObjectURL(blob);
link.setAttribute('download', filename);
document.body.appendChild(link);
link.click();
// 释放的 URL 对象以及移除 a 标签
URL.revokeObjectURL(link.href);
document.body.removeChild(link);
});
};
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。
文章由极客之家整理,本文链接:https://www.bmabk.com/index.php/post/66383.html