前端下载文件流 出现乱码 解决方案
1. 后端返回文件格式不是 utf-8
解决方案:后端加
2. 若添加 utf-8 后依旧乱码 请求配置中添加 responseType: 'arraybuffer',
export function downMode() {
return http.request({
url: baseUrl + 'downTemplate',
method: 'get',
responseType: 'arraybuffer',
});
}
下载
const blob = new Blob([data]); // 接口返回的文件流
const a = document.createElement('a');
a.style.display = 'none';
a.href = window.URL.createObjectURL(blob);
a.download = fileName || 'mode.xlsx';
a.click();
window.URL.revokeObjectURL(a.href);
a.remove();
原文地址:https://blog.csdn.net/weixin_46448762/article/details/140523358
免责声明:本站文章内容转载自网络资源,如本站内容侵犯了原著者的合法权益,可联系本站删除。更多内容请关注自学内容网(zxcms.com)!