Export2Zip
/* eslint-disable */ require('script-loader!file-saver'); import JSZip from 'jszip' export function export_txt_to_zip(th, jsonData, txtName, zipName) { const zip = new JSZip() const txt_name = txtName || 'file' const zip_name = zipName || 'file' const data = jsonData let txtData = `${th} ` data.forEach((row) => { let tempStr = '' tempStr = row.toString() txtData += `${tempStr} ` }) zip.file(`${txt_name}.txt`, txtData) zip.generateAsync({ type: "blob" }).then((blob) => { saveAs(blob, `${zip_name}.zip`) }, (err) => { alert('导出失败') }) }
handleDownload() { this.downloadLoading = true import('@/vendor/Export2Zip').then(zip => { const tHeader = ['Id', 'Title', 'Author', 'Readings', 'Date'] const filterVal = ['id', 'title', 'author', 'pageviews', 'display_time'] const list = this.list const data = this.formatJson(filterVal, list) zip.export_txt_to_zip(tHeader, data, this.filename, this.filename) this.downloadLoading = false }) }, formatJson(filterVal, jsonData) { return jsonData.map(v => filterVal.map(j => v[j])) }
https://github.com/PanJiaChen/vue-element-admin.git