当前位置: 首页 > Web前端 > HTML5

vue下载excel兼容360,QQ,IE10,IE11浏览器

时间:2023-04-04 22:55:47 HTML5

问题:360浏览器偶尔下载成功,console查看界面显示解决成功:兼容代码如下downloadExcel(dPath,param){//dPath--请求地址//param--请求路径this.$axios.post(dPath,param,{responseType:'arraybuffer'}).then(res=>{if(window.navigator&&window.navigator.msSaveOrOpenBlob){//兼容window.navigator.msSaveOrOpenBlob(blob,这是下载的文件名+'.xls')}else{varblobURL=window.URL.createObjectURL(blob)//将blob对象转换为URLvartempLink=document.createElement('a')//创建一个标签tempLink。style.display='none'tempLink.href=blobURLtempLink.setAttribute('download',thisisthedownloadedfilename)//给a标签加上download属性--文件名if(typeoftempLink.download==='undefined'){tempLink.setAttribute('target','_blank')}document.body.appendChild(tempLink)//给body加上a标签tempLink.click()//开始下载document.body.removeChild(tempLink)//下载后删除一个标签window.URL.revokeObjectURL(blobURL)}}).catch((error)=>{console.log(error)})},