1. js文件
export const download = (data: Blob, fileName: string, type: string) => {
const blob = new Blob([data], { type: mineType[type] })
window.URL = window.URL || window.webkitURL
const href = URL.createObjectURL(blob)
const downA = document.createElement('a')
downA.href = href
downA.download = fileName
downA.click()
window.URL.revokeObjectURL(href)
}
export const mineType = {
excel: 'application/vnd.ms-excel',
word: 'application/msword',
zip: 'application/zip',
html: 'text/html',
markdown: 'text/markdown'
}
2. 使用
download(res, '导出模板.docx', 'word')