仅为学习记录
type内容(部分):
示例
.xlsx
后缀的文件
const blob = new Blob([params], {
type: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
});
.xls
后缀的文件
const blob = new Blob([data], {
type: 'application/vnd.ms-excel',
});
具体实现
const url = window.URL.createObjectURL(blob)
const a = document.createElement('a');
a.href = url;
a.download = '文件名';
a.click();
window.URL.revokeObjectURL(url);
遇到的问题
导出的文件乱码或损坏:
在请求中加上
responseType: 'arraybuffer'
或者responseType: 'blob'
还有,我在处理文件损坏过程中,responseType位置写到其他请求上了,大家写的时候多注意哟。
其他资料
在群里问了大神,附上他的文件处理