VUE导出excel,IE11报错

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

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

VUE导出excel,IE11报错_第1张图片

解决方案如下:

            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

你可能感兴趣的:(vue)