blob转excel

1,124 阅读1分钟
   download (blob, fileName) {
      // 创建一个blob链接
      const blob1 = new Blob([blob], { type: 'application/vnd.ms-excel' })
      const url = URL.createObjectURL(blob1)
      const a = document.createElement('a')
      a.setAttribute('download', url)
      a.href = url
      a.style.display = 'none'
      a.setAttribute('download', fileName + '.xls')
      document.body.appendChild(a)
      a.click()
      document.body.removeChild(a)
      // 每次调用URL.createObjectURL,都会创建一个新的URL对象,浏览器内存中会保持对该对象的引用
      // 只有在document销毁时,才会释放此部分内存
      // 在考虑性能的情况下,在url使用结束后,最好释放此部分内存
      URL.revokeObjectURL(url)
    },

调用获取bolb接口

  responseType: 'blob',
  headers: {
    'Content-Type': 'application/json'
  }