function downloadFile(url,filename) { const xhr = new XMLHttpRequest(); xhr.open('GET', url, true); xhr.responseType = 'blob'; xhr.onload = function() { if (xhr.status === 200) { // 创建一个a标签 const a = document.createElement('a'); a.href = window.URL.createObjectURL(xhr.response); a.download = filename; document.body.appendChild(a); a.click(); document.body.removeChild(a); } }; xhr.send(); } export default downloadFile;