<el-button
@click="downloadExcel(flowMsg.applyForm.fileUpload)"
type="primary"
size="medium"
>下载</el-button
>
import axios from 'axios'
//下载
downloadExcel(params) {
axios({
url: `/activity/file/download?fileName=${params}`, //去掉首个
headers: {
Authorization: sessionStorage.getItem('token'),
'content-type': 'multipart/form-data', //'content-type':'application/x-www-form-urlencoded',
},
responseType: 'blob', //important
method: 'get',
})
.then((res) => {
const myURL = window.URL || window.webkitURL
const link = document.createElement('a')
link.href = myURL.createObjectURL(res.data) //为了获取这个值需要后台设置一下响应头'Access-Control-Expose-Headers':'Content-Disposition'//暂时这么做……
let fileName = params
if (!fileName) {
const matches =
res.headers['content-disposition'] &&
res.headers['content-disposition'].match(
/attachment;?filename=([^"]*)/
)
fileName = matches && matches[1]
if (fileName) fileName = decodeURI(fileName)
}
link.download = fileName || '模板.xlsx'
link.click()
})
.catch((e) => {
console.log(e)
})
},