一. 下载包
npm i jszip -S
二. 引入包
<script src="jszip/jszip.min.js"></script>
三. 解析zip文件
httpRequest({ file }) {
this.loading = true;
const _this = this;
JSZip.loadAsync(file, {
decodeFileName: function (bytes) {
return iconv.decode(bytes, "gbk");
},
}).then(function (zip) {
_this.loading = false;
zip.forEach((val) => {
zip.files[val].async("blob").then(function (con) {
const file = new window.File([con], val);
const id_number = val.split("_")[0];
const user_name = val.split("_")[1].split(".")[0];
_this.userList.push({
user_name,
id_number,
file,
name: val,
});
_this.total++;
});
});
});
},