download(url) {
var filename = "";
var name = url.split("/")[url.split("/").length - 1];
if (name.indexOf(".copy") != "-1") {
filename = name.split(".copy")[0];
} else {
filename = name;
}
return fetch(url).then((res) =>
res.blob().then((blob) => {
let a = document.createElement("a");
let url = window.URL.createObjectURL(blob);
if (window.navigator.msSaveBlob) {
// ie下载
try {
window.navigator.msSaveBlob(blob, filename);
} catch (e) {
console.log(e);
}
} else {
// 其他下载
a.href = url;
a.download = filename;
a.click();
window.URL.revokeObjectURL(url);
}
})
);
},
es6兼容fetch
npm install --save isomorphic-fetch es6-promise
import "isomorphic-fetch"