概述
如何动态获取导出文件名称
这里我是在vue项目中处理的
一般后端会将 导出的文件名称放在heard里面,所以取的时候也得去heard里面取
这个时候,不能用我们分装的请求方式取拿了,因为项目中请求的数据一般会把没用的数据过滤掉,
//
导出
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('导出失败')
})
},
最后
以上就是漂亮水杯为你收集整理的导出文件,名称动态获取的全部内容,希望文章能够帮你解决导出文件,名称动态获取所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复