问题
const zip2 = new JSZip();
for(const item of this.paths) {
const { md5Name, zipEntry } = item;
const blob = await zipEntry.async('blob');
zip2.file(md5Name, blob);
console.log('-----', zip2);
}
console.log('before zip2.generateAsync');
zip2.generateAsync({type: 'blob'}).then(zipFile => {
console.log('zip2.generateAsync');
// 创建链接
const link = document.createElement('a');
// 设置链接的下载内容
link.href = URL.createObjectURL(zipFile);
// 设置链接的下载文件名
link.download = `离线包-${this.addTempForm.urlPre}.zip`;
// 执行下载
link.click();
}).finally(() =>{
this.loading = false;
});
以上生成的zip包很大???
原因
参考:
generateAsync默认是不会压缩的
stuk.github.io/jszip/docum… 示例用法默认不会压缩,需要增加压缩选项