vue axios下载后端word文件
vueaxios下载后端word文件
·
const exportword = async () =>{
window.ajax1({
url: '/api/DownloadYearWordReport/Download?year=' + year.value + '&half=' + half.value,
method: 'get',
responseType: 'blob',
})
.then(res => {
if (!res.data) {
return
}
let url = window.URL.createObjectURL(new Blob([res.data]))
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', 'exprotword.docx')
document.body.appendChild(link)
link.click()
// 释放URL对象所占资源
window.URL.revokeObjectURL(url)
// 用完即删
document.body.removeChild(link)
})
.catch(res => { console.log(res)})
};
更多推荐
已为社区贡献3条内容
所有评论(0)