VUE导出excel,IE11报错

   在做vue结合后台做导出功能时,chrome能正常导出,但是IE11却报异常:Unhandled promise rejection Error: 拒绝访问。

经过分析后发现,代码执行到click函数抛异常了。

解决方案如下:

            var disposition = res.headers['content-disposition'];
            var fileName = decodeURI(disposition.substring(disposition.indexOf('filename=') + 9, disposition.length));
            let blob = new Blob([res.data],{type: 'application/vnd.ms-excel'});

            if(window.navigator && window.navigator.msSaveOrOpenBlob){
              navigator.msSaveBlob(blob, fileName)
            }else{
              const link = document.createElement('a');
              link.style.display = 'none';
              var href =URL.createObjectURL(blob);
              link.href =href;
              link.setAttribute('download',  fileName);
              document.body.appendChild(link);
              link.click();
              document.body.removeChild(link);
              window.URL.revokeObjectURL(href); //释放掉blob对象

 参考:https://blog.csdn.net/sinat_41200024/article/details/89175009

            https://segmentfault.com/q/1010000010545472

发布了70 篇原创文章 · 获赞 63 · 访问量 23万+

猜你喜欢

转载自blog.csdn.net/xiaoxiangzi520/article/details/97637384
今日推荐