const downloadExcelFile = async function (api, params, name) {
const res = await this.$get(api, params, { responseType: 'blob'});
try {
let url = window.URL.createObjectURL(new Blob([res]))
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', `${name}`)
document.body.appendChild(link);
link.click() //执行下载
window.URL.revokeObjectURL(link.href) //释放url
document.body.removeChild(link) //释放标签
} catch (e) {
this.$notify.error({
title: '错误',
message: '下载文件失败'
});
}
}
js通过a标签下载文件
最新推荐文章于 2024-04-29 18:19:28 发布