前端下载excel

export function fileLocalDownLoad(data, fileName) {
  const blob = new Blob(data)
  let downloadElement = document.createElement('a')
  let href = window.URL.createObjectURL(blob)
  downloadElement.href = href
  downloadElement.download = decodeURIComponent(fileName)
  document.body.appendChild(downloadElement)
  downloadElement.click()
  document.body.removeChild(downloadElement)
  window.URL.revokeObjectURL(href)
}
 api
        .exportExcel(params)
        .then((response) => {
          this.exportLoading = false
          this.exportText = '数据导出'
          //application/vnd.ms-excel  application/octet-stream
          if (response.data.type == 'application/vnd.ms-excel') {
            fileLocalDownLoad([response.data], (this.dataForm.year + '数据.xlsx'))
            // const url = window.URL.createObjectURL(new Blob([response.data]))
            // const link = document.createElement('a')
            // link.href = url
            // link.setAttribute('download', '数据.xlsx')
            // document.body.appendChild(link)
            // link.click()
            // document.body.removeChild(link);
            // window.URL.revokeObjectURL(url);
            this.$message({
              type: 'success',
              message: '导出成功'
            })
          } else {
            this.$message.error('导出失败')
          }

        })
export function exportExcel (params) {
    return request({
        url: '/export',
        method: 'GET',
        responseType: 'blob',
        params
    })
}
上一篇:java: create pdf using itextpdf 2.1.7 Library


下一篇:09.js基础知识-BOM对象