下载文件流导出xls或其他格式

axios.post(url
            , fd
            , {
              headers: {
                'Content-Type': 'multipart/form-data'
              },
              responseType: 'blob'
            }
          ).then(res=>{
              const blob = new Blob([res.data], { type: 'application/vnd.ms-excel' })
              const date = new Date()
              const url = window.URL.createObjectURL(blob)// 为文件流创建构建下载链接
              const link = document.createElement('a')// 创建a标签
              link.style.display = 'none'
              link.href = url
              link.setAttribute('download', `名称-${date.getFullYear()}-${date.getMonth() + 1}-${date.getDate()}.xls`)// 设置a标签的下载动作和下载文件名
              document.body.appendChild(link)
              link.click()// 执行下载
              document.body.removeChild(link)// 释放标签
})
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容