项目场景:
在项目中 使用到了xlsx-style 出现了 报错
问题描述
点击把数据生成excel的时候出现的报错,
jszip.min.js:13 Uncaught (in promise) Error: This method has been removed in JSZip 3.0, please check the upgrade guide.
at n.generate (jszip.min.js:13:16600)
at xlsx.js:11773:1
at Object.rh [as write] (xlsx.js:11784:1)
at t.export_json_to_excel (Export2Excel2.js:292:20)
at export2Excel.vue:595:1
原因分析:
在xlsx-style 里面引入了JSZip ,引入方式有问题, 上面的报错信息都是使用到的地方,错误的源头是引入方式。因为。jszip 版本 3.0以下的和3.0以及以上 两种不同,xlsx-style的作者没有及时维护产生的
解决方案:
在node_modules文件夹中找到,xlsx-style文件夹 在找到 xlsx.js
node_modules\xlsx-style\xlsx.js
找到 文件中的 1334行 到1342行
原本写法
var _fs, jszip;
if(typeof JSZip !== 'undefined') jszip = JSZip;
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
if(has_buf && typeof jszip === 'undefined') jszip = require('js'+'zip');
if(typeof jszip === 'undefined') jszip = require('./js'+'zip').JSZip;
_fs = require('f'+'s');
}
}
修改后写法
var _fs, jszip;
if(typeof JSZip !== 'undefined') jszip = JSZip;
if (typeof exports !== 'undefined') {
if (typeof module !== 'undefined' && module.exports) {
if(has_buf && typeof jszip === 'undefined') jszip = require('js'+'zip');
if(typeof jszip === 'undefined') jszip = require('./js'+'zip');
_fs = require('f'+'s');
}
}