使用AJAX下载文件直接粘贴代码download(url,fileName,type){axios({method:'get',url:url,responseType:'blob',headers:{'content-disposition':`attachment;filename=${type}`,'content-type':'application/x-download;charset=utf-8'}}).then(res=>{constblob=newBlob([res.data],{type:type})consturl=window.URL.createObjectURL(blob)constlink=document.createElement('a')link.style.display='none'link.href=url链接.setAttribute('download',fileName)document.body.appendChild(link)link.click()document.body.removeChild(link)})}项目中使用的vue使用axios后台直接返回文件二进制流关于参数url文件下载url路径fileName文件名类型文件类型
