下载后台返回的excel文件

//下载后台返回的excel文件
export const exportExcel = (url, data = {}, name = 'bill', module = 'pay') => {
  $.get({
    url: UrlPrefix[module] + url,
    data,
    xhrFields: { responseType: 'blob' },
    success: function (res) {
      const aLink = document.createElement('a')
      let blob = new Blob([res], { type: 'application/vnd.ms-excel' })
      aLink.href = URL.createObjectURL(blob)
      aLink.setAttribute('download', name + '.xlsx')
      document.body.appendChild(aLink)
      aLink.click()
      document.body.removeChild(aLink)
      URL.revokeObjectURL(aLink.href)
    },
  })
}
posted @ 2020-11-02 17:40  詹姆斯小皇帝  阅读(266)  评论(0编辑  收藏  举报