var typ =
type || ‘application/vnd.openxmlformats-officedocument.spreadsheetml.sheet’;//xlsx script-loader(D) xlsx(S) file-saver(S)
type: “application/zip”(responseType: “arraybuffer”)(xxx.zip)
type: “text/plain”(xxx.txt)
let blob = new Blob([res.data],{type: ‘application/vnd.ms-excel’});
1.下载文件流
if (!!window.ActiveXObject || “ActiveXObject” in window) {
window.navigator.msSaveOrOpenBlob(blob, ‘fileName’);
} else {
const link = document.createElement(‘a’);
//link.style.display = ‘none’;
link.href = URL.createObjectURL(blob);
link.setAttribute(‘download’, ‘xxx.xls’);
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(url)//释放blob对象
}
window.location = url
2.url下载
1).function downLoad(downUrl, fileName) {
let a = document.createElement(“a”)
if (fileName) {
a.download = fileName
}
(document.body || document.documentElement).appendChild(a);
a.href = downUrl
a.target = ‘_parent’;
a.click()
a.remove()
}
downLoad(URL, ‘test.xlxs’)
2).window.open() window.location