1.后端设置response的content-type=“application/octet-stream”,返回类型是文件流
2.后端设置Access-Control-Expose-Headers: Content-Disposition,这样前端才能读到header中content-disposition
2.前端请求接口的时候:设置 responseType: 'blob',返回类型是blob
const blob = new Blob([res.data])
const fileName = res.headers['content-disposition'].split(';')[1].split('=')[1]
if ('download' in document.createElement('a')) { // 非IE下载
const elink = document.createElement('a')
elink.download = fileName
elink.style.display = 'none'
elink.href = URL.createObjectURL(blob)
document.body.appendChild(elink)
elink.click()
URL.revokeObjectURL(elink.href)
document.body.removeChild(elink)
} else { // IE10+下载
navigator.msSaveBlob(blob, fileName)
}