Excel文件在IE下导不出来

handleDownload(){
    let fileName='222';
    //fileName=encodeURIComponent(fileName);
    console.log(fileName);
    //导出
    if(this.ID){
      this.toDownload(this.uploadUrl,this.ID,fileName+'.xlsx')
    }else{
        this.$message.error('没有数据,无法导出!');
    }
},
toDownload(url, data, fileName) {
    return new Promise((resolve, reject) => {
        axios({
            method: "get",
            url: url,//请求后端接口url
            params:{ChlinicalID:data},
            responseType: 'blob'
        })
        .then(res => {
            let reader = new FileReader();
            let data = res.data;
            console.log(res);
            reader.onload = e => {
                if (e.target.result.indexOf('Result') != -1 && JSON.parse(e.target.result).Result == false) {
                    // 进行错误处理
                } else {
                    if (!fileName) {
                        let contentDisposition = res.headers['content-disposition'];
                        if (contentDisposition) {
                            fileName = window.decodeURI(res.headers['content-disposition'].split('=')[2].split("''")[1], "UTF-8");
                        }
                    }
                    this.executeDownload(data, fileName);
                }
            };
            reader.readAsText(data);
            resolve(res.data);
        })
    });
},
 //  模拟点击a 标签进行下载
executeDownload(data, fileName) {
  if (!data) {
         return
     }
     var blobData=new Blob([data]);
     if (navigator.msSaveOrOpenBlob) {//允许用户在客户端上保存文件,IE
         //IE浏览器
         navigator.msSaveOrOpenBlob(blobData,fileName);
     } else {
         //其他浏览器
         let url = window.URL.createObjectURL(blobData);
         console.log('url',url);
         let link = document.createElement('a');
         link.style.display = 'none';
         link.href = url;
         link.setAttribute('download', fileName);
         document.body.appendChild(link);
         link.click();//IE下不支持该方法
         document.body.removeChild(link);
     }
 },
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容