我是靠谱客的博主 漂亮水杯,这篇文章主要介绍导出文件,名称动态获取,现在分享给大家,希望可以做个参考。

如何动态获取导出文件名称

这里我是在vue项目中处理的
一般后端会将 导出的文件名称放在heard里面,所以取的时候也得去heard里面取
这个时候,不能用我们分装的请求方式取拿了,因为项目中请求的数据一般会把没用的数据过滤掉,

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
// 导出 templateDownload () { axios({ method: 'get', url: '/api' + publicRequest + '/rhd/task/record/non/routine/detail/excel', params: { id: this.detailId }, responseType: 'blob' }).then((res) => { const link = document.createElement('a') const blob = new Blob([res.data], { type: 'application/vnd.ms-excel' }) // 获取heads中的filename文件名 const temp = res.headers['content-disposition'].split(';')[1].split('filename=')[1] // 通过 decodeURI 转码汉字 const fileName = decodeURI(temp) link.style.display = 'none' link.href = URL.createObjectURL(blob) // 设置文件名称 link.setAttribute('download', fileName) document.body.appendChild(link) link.click() document.body.removeChild(link) }).catch(() => { this.$message.error('导出失败') }) },

最后

以上就是漂亮水杯最近收集整理的关于导出文件,名称动态获取的全部内容,更多相关导出文件内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(61)

评论列表共有 0 条评论

立即
投稿
返回
顶部