
本文共 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���������
������������������������������������������������������������������������������������������������������
发表评论
最新留言
关于作者
