function download (href, name) {
// 通过ajax重新请求文件地址传入blob类型
const xhr = new XMLHttpRequest()
xhr.open('GET', href, true)
xhr.responseType = 'blob'
xhr.onload = () => {
if (xhr.status === 200) {
saveAs(xhr.response, name)
}
}
xhr.send()
};
function saveAs(data, name) { // 转换流并下载
// console.log(data)
const urlObject = window.URL || window.webkitURL || window;
const export_blob = new Blob([data]);
const save_link = document.createElement('a')
save_link.style.display = 'none';
save_link.href = urlObject.createObjectURL(export_blob);
save_link.download = name;
document.body.appendChild(save_link);
save_link.click();
document.body.removeChild(save_link);
}
05-11