实现代码:
let url = window.URL.createObjectURL(new Blob([’\uFEFF’+res], {type: ‘text/csv’}))
let link = document.createElement(‘a’)
link.style.display = ‘none’
link.href = url
link.setAttribute(‘download’, 话费供应商模板${new Date().getTime()}.csv
)
document.body.appendChild(link)
link.click()
注释:
type:(可以用)
‘.csv, application/vnd.openxmlformats-officedocument.spreadsheetml.sheet, application/vnd.ms-excel’
\uFEFF(解决乱码)
微软系产品类似Excel会先识别该bom头,然后才能认识你,而针对csv格式文件,通过blob新建下载url的时候,加一个bom头编码