方法一:
let url = window.UL_CONFIG.BASEURL
window.open(`${url}/api/etask-download?id=${id}`)
方法二:
download(id) {
let params = new URLSearchParams()
params.append("id", id)
fileDownload(params).then(response => {
const fileName = response.headers['content-disposition'].split('=')[1]
const blob = new Blob([response.data], { type: 'application/octet-stream;charset=utf-8' })
const url = window.URL.createObjectURL(blob)
var link = document.createElement("a")
link.href = url
link.download = fileName
link.click();
window.URL.revokeObjectURL(url)
// this.getTaskList()
setTimeout(async () => {
await this.getTaskList()
}, 2000);
}).catch(error => this.$message.error(error))
},
// 文件下载
export function fileDownload(query) {
return axios({
url: "/api/etask-download",
method: "GET",
params: query,
responseType: "blob", // 重点!!!!!
});
}