添加请求拦截
axios.interceptors.response.use(response => {
if (response.headers['content-type'] === 'application/csv;charset=UTF-8') {
return response
})
通过请求获取数据源后
exportFile = (res, name) => {
let name0 = decodeURI(name)
var BOM = '\uFEFF'
const blob = new window.Blob([BOM + res], { type: 'text/csv' })
const href = URL.createObjectURL(blob)
window.URL.createObjectURL(new window.Blob(['\uFEFF' + blob]))
let a = document.createElement('a')
a.href = href
let newName = name0.replace(/%40/g, '@')
a.download = `${newName}`
a.click()
URL.revokeObjectURL(href)
a = null
}