Vue 导出blob兼容IE

    axios.get(url, {
        params: param,
        responseType: 'arraybuffer'
      }).then((response) => {
          loading.close();
          const csvData = new Blob([response.data], {type: 'application/x-xlsx'})//response.data要导出的内容
          const file_name = 'xxx导出' + '.xlsx';
          // for IE
          if (window.navigator && window.navigator.msSaveOrOpenBlob) {
              window.navigator.msSaveOrOpenBlob(csvData, file_name);
          }
          // for Non-IE (chrome, firefox etc.)
          else {
              var a = document.createElement('a');
              var url = window.URL.createObjectURL(csvData);
              a.href =  url;
              a.download = file_name;
              a.click();
              a.remove();
              window.URL.revokeObjectURL(url);
          }
      }).catch((error) => { })

posted on 2019-12-25 11:28  lyuyi  阅读(1091)  评论(0编辑  收藏  举报

导航