function downFile(urlPath, query, filename) {
return new Promise((resolve, reject) => {
const newOptions = {
method: 'POST',
body: JSON.stringify(query),
headers: {
Accept: '*/*',
'Content-Type': 'application/json; charset=utf-8',
"access-token": LOGIN_TOKEN(),
},
}
fetch(urlPath, newOptions).then(res => {
return res.blob()
}).then(data => {
const url = window.URL.createObjectURL(data)
const link = document.createElement('a')
link.style.display = 'none'
link.href = url
link.setAttribute('download', filename || 'file.xlsx')
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
resolve()
}).catch((err) => {
reject(err)
})
})
}
POST方式下载文件
于 2024-01-04 10:37:34 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)