那在前端需要用到这些数据时,如何解压文件从而读取文件里面的内容呢?这里推荐一个插件JSzip,具体使用方法如下,有更好的方式欢迎大家留言交流!1、安装JSzipcnpm i jszip -S 2、安装requestcnpm install request --save-dev3、引入JSzip和request import JSZip from 'jszip' import request from 'request'4、开始解压(file为zip的地址,logName为解压后需要打开的文件名)zip(file) { let logName = '', index=file.lastIndexOf("/"); logName = file.substring(index+1,file.length-4)+'.log' request({ method : "GET", url : 'file', encoding: null }, function (error, response, body) { if(error || response.statusCode !== 200) { return; } JSZip.loadAsync(body).then(function (zip) { return zip.file(logName).async("string")//根据文件名进行读取解析文件 }).then(function (text) { console.log(text)//text即为解析出来的日志文件 }); }); }效果图
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)