前端文件下载
// 下载文件
export function downloadFile(url, fileName, data) {
axios({
method: 'post',
url,
responseType: 'blob',
data
}).then((res) => {
const blob = new Blob([res.data], {
type: 'application/vnd.ms-excel;charset=utf8'
})
const objectUrl = URL.createObjectURL(blob)
downloadFunction(objectUrl, fileName)
})
}
export function downloadFunction(content, filename) {
const a = document.createElement('a')
a.href = content
a.download = filename
document.body.append(a)
a.click()
document.body.removeChild(a);
}
学而不思则罔,思而不学则殆!