前端使用jszip解压zip文件获取file格式文件#安装jszipnpm install jszip --save#简单的使用示例import JSZip from "jszip";let zip = new JSZip();zip.loadAsync(file).then((res) => { console.log(res.files); res.forEach((ele, obj) => { if (!obj.dir) {//判断是否为文件 /** 转换成Base64方式,根据需求引用 let binary = ''; let bytes = obj._data.compressedContent; for (let index = 0; index < bytes.length; index++) { const element = bytes[index]; binary += String.fromCharCode(element); } binary = window.btoa(binary); */ // 压缩包内文件名称 let fileName = obj.name; //压缩包内文件大小 let unsize = obj._data.uncompressedSize / 1024; let fileSize = unsize.toFixed(2) + "KB"; //下载操作 let base = res.file(obj.name).async('blob'); //.async("string") // 此处是压缩包中的testtxt.txt文件,以string形式返回其内容,此时已经可以获取zip中的所有文件了 base.then(rr => { saveAs(rr, obj.name); }) } })})