沐若清辰
人生如茶,浓也好,淡也好,各有味道
 1. import XLSX from 'xlsx'
  import ES6Promise from 'es6-promise'

 2.入参增加 responseType: 'blob',
  例如: exportTemporaryList: params => {
    return api.get({url: '/temporary/exportTemporaryList', params, responseType: 'blob', headers: {'Content-Type': 'application/json'}})
  },

3. organApi.exportTemporaryList(dataInformation) // 重新获取下级节点
          .then((res2) => {
             let downloadFileName =  'aaaa.xlsx' // 导出后文件名
                  if ('msSaveOrOpenBlob' in navigator) { // Microsoft Edge and Microsoft Internet Explorer 10-11
                    window.navigator.msSaveOrOpenBlob(res2, downloadFileName)
                  } else { // standard code for Google Chrome, Mozilla Firefox etc
                    var blob = new Blob([res2], {type: 'application/vnd.ms-excel'})
                    var downloadElement = document.createElement('a')
                    var href = window.URL.createObjectURL(blob) // 创建导出的链接
                    downloadElement.href = href
                    downloadElement.download = downloadFileName
                    document.body.appendChild(downloadElement)
                    downloadElement.click() // 点击导出
                    setTimeout(() => {
                      document.body.removeChild(downloadElement) // 导出完成移除元素
                      window.URL.revokeObjectURL(href) // 释放掉blob对象
                    }, 500)
                  }
        })
 

  

posted on 2020-09-18 17:28  沐若清辰  阅读(616)  评论(0编辑  收藏  举报