一. 下载或导出后台返回的二进制流文件-excel
//axios请求后台数据,处理后台返回的二进制流文件数据
exportExcel().then((res) => {
let url = window.URL.createObjectURL(new Blob([res],{
type: "application/vnd.ms-excel"}))
let link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', 'excel.xls')
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
})
二. 根据文件链接(文件地址)进行下载
//例如,文件下载地址为`/file/${文件id}/download`
handleDownload () {
let link = document.createElement("a");
link.style.display = "none"