如何下载后端返回的文件流
小于 1 分钟
如何下载后端返回的文件流
请求投的类型一定要换一种方式不然会存在乱码
$.ajax({ url: url, type: "POST", data: datas, cache: false, processData: false, contentType: false, xhrFields: { responseType: "arraybuffer" }, })
利用blob格式,通过a标签来下载文件
let blob = new Blob([res], { type: 'application/xlsx' }) // 使用 blob
let url = window.URL.createObjectURL(blob)
// 重命名文件名称
let a = document.createElement('a') // l
a.setAttribute('href', url)
a.setAttribute('download', '数据导出表.xls')
a.click()