vue 导出excel (公共方法)
// 导出文 -res
export function handleExp (res) {
// 获取导出文件名称
const file = store.state.headerContent
const filename = file['content-disposition'].split(';')[1].split('filename=')[1].split('"')[1] || file['content-disposition'].split(';')[1].split('filename=')[1]
// 转为bolb对象
const en = decodeURIComponent(filename)
const blob = new Blob([res], { type: 'application/vnd.ms-excel' })
if (window.navigator.msSaveOrOpenBlob) {
// 兼容ie
window.navigator.msSaveBlob(blob, en)
} else {
const downloadElement = document.createElement('a')
const href = window.URL.createObjectURL(blob) // 创建下载的链接
downloadElement.href = href
downloadElement.download = en // 下载后文件名
document.body.appendChild(downloadElement)
// 此写法兼容火狐
const evt = document.createEvent('MouseEvents')
evt.initEvent('click', false, false)
downloadElement.dispatchEvent(evt)
document.body.removeChild(downloadElement)
}
}