方法一 blob
const link = document.createElement('a')
var blob = new Blob([data],{type:XXX})
if(window.navigator.msSaveBlob/msSaveOrOpenBlob){
window.navigator.msSaveBlob/msSaveOrOpenBlob(blob,‘文件名’)
} else {
let url = window.URL.createObjectURL(blob)
link.href = url
link.download = '文件名'
link.click()
window.URL.revokeObjectURL(url)
}
方法二 js-file-download
npm install js-file-download --save
import fileDownload from 'js-file-download'
axios.post(postUrl, params, {responseType: 'arraybuffer'}).then(res => {
fileDownload(res.data, 'xxx.xls')
})