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 更加灵活、体验好
- 直接创建下载链接;
- 支持
Blob和Data URI(允许开发者方便地将JavaScript生成的数据(如JSON或字符串)直接转换为文件并下载,而不必依赖服务器端生成文件。例如,可以方便地exporting CSV/Excel文件) - 更好的浏览器兼容性
- 自定义文件名