vue+post请求导出excel

重点:responseType: 'blob'

    pageExport () {
      this.$axios.post(this.gwu.cont.url.electricityExport, this.param, {responseType: 'blob'})
        .then((res) => {
          const blob = new Blob([res], {type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8'})
          const downloadElement = document.createElement('a')
          const href = window.URL.createObjectURL(blob)
          // filename自定义
          let datestr = this.gwu.dateFormat.dtsyyyyMMdd(new Date())
          let filename = this.$t('message.ELECTRICITYMETER').concat(datestr).concat('.xlsx')
          downloadElement.style.display = 'none'
          downloadElement.href = href
          downloadElement.download = filename
          document.body.appendChild(downloadElement)
          downloadElement.click()
          document.body.removeChild(downloadElement)
          window.URL.revokeObjectURL(href)
          console.info('export ok!!!!')
        }).catch(() => {
          console.info('export failed!!!!')
        })
    },
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容