axios.get(`/xxx-xxx${this.downloadUrl}`, {
headers: {
'Authorization': this.$store.getters.token
},
responseType: 'blob'
}).then((res) => {
const temp =
res.headers['content-disposition'].split('filename=')[1]
const fileName = decodeURIComponent(temp)
const link = document.createElement('a')
const blob = new Blob([res.data], { type: 'application/vnd.ms-excel' })
link.style.display = 'none'
link.href = URL.createObjectURL(blob)
link.download = fileName // 下载后文件名
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
})
axios通过接口下载excal
最新推荐文章于 2024-03-20 09:10:15 发布