blob 文件下载
作者:互联网
axios({
method: 'get',
url:
process.env.VUE_APP_BASE_API +
'/tb-nationwide/downloadEvaluationTaskRecord',
params: param,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-Access-Token': vue.ls.get(ACCESS_TOKEN),
},
responseType: 'blob',
}).then((res) => {
console.log(res)
const fileName = res.headers['content-disposition']
? window.decodeURI(
res.headers['content-disposition'].split('=')[1],
)
: '渲染全国数据空文件.zip'
const extension = fileName.split('.')[1]
if (extension == 'csv') {
downloader(res.data, fileName)
} else {
downloader(
new Blob([res.data], { type: 'application/' + extension }),
fileName,
)
}
})
downloader为
import downloader from 'downloadjs'
标签:文件,const,extension,downloader,res,fileName,headers,blob,下载 来源: https://www.cnblogs.com/chenlongsheng/p/16553370.html