原因:编码格式问题,需要改为utf-8 bom
// Create blob with utf8-bom 编码
const createBlobWithBOM=(data, mimeType)=> {const bom = [0xEF, 0xBB, 0xBF];const bomArray = new Uint8Array(bom);const dataArray = new TextEncoder().encode(data);const combinedArray = new Uint8Array(bomArray.length + dataArray.length);combinedArray.set(bomArray);combinedArray.set(dataArray, bomArray.length);const blob = new Blob([combinedArray], { type: mimeType });return blob;
}
//使用
let csvMapInfo = [[],[],[]]
const url = createBlobWithBOM(csvMapInfo, 'text/csv') //csv 编码转换
const urlWithBOM = window.URL.createObjectURL(url)
const link = document.createElement('a')
link.href = urlWithBOM
link.setAttribute('download', '数据表')
document.body.appendChild(link)
link.click()