JSZip根据文档路径生成压缩包文件
参考自JSZip文档
首先下载JSZip库
npm install jszip or yarn add jszip
const front = [{directory: 'front/src/api/example'},{directory: 'front/src/views/example/example1'},{directory: 'front/src/views/example/single-crud-management'}
]
function downlaodZip() {const zip = new JSZip()front.forEach((value, index) => {zip.file(value.directory + '/' + index + '.txt', 'test content')})zip.generateAsync({type: 'blob'}).then(blob => {saveAs(blob, 'example.zip')}, err => {console.error(err)})}
注意:
saveAs是从filesaver这个库引用的
npm install file-saver or yarn add file-saver
效果如下: