前端获得url地址下载方式

118 阅读1分钟

// url地址下载方式 getFileAndDownload(fileName, url) { var x = new XMLHttpRequest(); x.open("GET", url, true); x.responseType = "blob"; x.onload = function (e) { var blob = x.response; if ("msSaveOrOpenBlob" in navigator) { // IE导出 window.navigator.msSaveOrOpenBlob(blob, fileName); } else { const a = document.createElement("a"); a.download = fileName; a.href = URL.createObjectURL(blob); document.body.appendChild(a); a.click(); document.body.removeChild(a); } }; x.send(); },