1.原理
利用decodeURIComponent() 函数可对 encodeURIComponent() 函数编码的 URI 进行
2.封装方法exportFile
/**
* @param {blobObj} blobObj eg 文件流
* @param {string} fileName eg 文件名 filename=1111.xlsl 或者 filename=1111.zip
* @returns {Boolean}
*/
export function exportFile (blobObj, fileName) {
const downloadElement = document.createElement('a')
const href = window.URL.createObjectURL(blobObj)
downloadElement.href = href
downloadElement.download = decodeURIComponent(fileName.split('filename=')[1])
document.body.appendChild(downloadElement)
downloadElement.click()
document.body.removeChild(downloadElement)
window.URL.revokeObjectURL(href)
}
3.页面使用
exportFile(res, 'filename=11111.zip')