import fileDownload from 'js-file-download';
// 下載模板
const downTemplate = async () => {
const res = await computeTemplateMatchingFileTemplate({resType: 'blob'}) as any;
fileDownload(res.data, '');
};
window.open 打開url 新窗口/標簽頁默認行為,頁面會抖動;有時會被攔截;無法處理非http資源等。
js-file-download 更加靈活、體驗好
- 直接創(chuàng)建下載鏈接;
- 支持
Blob和Data URI(允許開發(fā)者方便地將JavaScript生成的數(shù)據(jù)(如JSON或字符串)直接轉(zhuǎn)換為文件并下載,而不必依賴服務(wù)器端生成文件。例如,可以方便地exporting CSV/Excel文件) - 更好的瀏覽器兼容性
- 自定義文件名