vue 导出Excel乱码问题解决方案
发布日期:2021-05-10 09:46:42 浏览次数:9 分类:精选文章

本文共 3692 字,大约阅读时间需要 12 分钟。

���������Excel������������������������

������������������Vue���������������������������������������������������������������������������������Excel������������������������������������������������������������������������������������������������������������������������������������������������������������������

������������

������������������������������������������������������������������

1���������������������������������������������������������������������������������������������������Excel������������������������������������������Content-Type���application/vnd.ms-excel������������������������wrong Content-Type������������������������������������������������������

2���������������������������������������������������������������������������Content-Type���������������������������������������������application/octet-stream������������������������������������

3������������������������������������������������������������������������������������������������_blob���������������������������������������������������

������������������

���������������������������������������������������������������������������������������

������������������������������������������������������������������

1������Axios���������������������������������

������Axios���responseType���'blob'��������������������������������������������������������� downloadable���������

// ���������������������������Axios������axios({  method: 'post',  url: '/api/excel',  responseType: 'blob',  headers: {    'Content-Type': 'application/vnd.ms-excel',  },}).then(response => {  // ���������������  handleExcelDownload(response.data);});

2������������������������

������������������Blob������������������������������������������������

// ��������� blobDownload(data, name)function blobDownload(data, name) {  name = name || 'default_filename';    // ������Blob������  const blob = new Blob([data], {     type: 'application/vnd.ms-excel'   });    // ������������������  const downloadUrl = window.URL.createObjectURL(blob);    // ������������������  const a = document.createElement('a');  a.href = downloadUrl;  a.download = name + '.xls';  document.body.appendChild(a);  a.click();  document.body.removeChild(a);    // ������������  window.URL.revokeObjectURL(downloadUrl);}

3���������Content-Type���

���������������������������Content-Type������������������������Excel���������������MIME������������������

headers: {  'Content-Type': 'application/vnd.ms-excel charset=utf-8'}

���������������������������responseType:'blob'���������������headers���������������������������������������������responseType���������Axios���������������������������������������headers������

������������

������������������������������������������������������������������

���������������������������

1���������������������������������Excel������������������������UTF-8������������������������������������������������������������������������������������������UTF-8���������

2���Content-Type���������������������������������������������������������������������Content-Type������������������������������������

3������������������������������������������������������������������������������������������������������������������������

������������������������������������������������������������������Excel������������������������������������

���������������������������������������������

1������������������������������Content-Type���������������������������������������������������������

2���������������������������Content-Type������������Blob���������������������������Excel MIME���������

3���������������������������������������UTF-8���������

������������������������������������������������������������������������������������������������������

上一篇:golang type的用法理解(陆续补充)
下一篇:vue 打包 报错ERROR in static/js/app.xxxx.js from UglifyJs解决方案

发表评论

最新留言

初次前来,多多关照!
[***.217.46.12]2025年04月09日 07时06分12秒