同事做文件下载
下载后的文件 无法打开,报 文件已损坏 或 格式不正确
vue的文件下载, 这里一定要用get 否则下载的文件会打不开
axios.get(filePath, {
responseType: 'arraybuffer'
}).then(res => {
let blob = new Blob([res.data], { type: 'application/vnd.ms-exce' })
let link = document.createElement('a')
let fileName = '文件名.xls'
link.href = window.URL.createObjectURL(blob)
link.download = decodeURIComponent(fileName)
link.click()
})
网友评论