使用 xlsx-style 报JSZip 3.0 报错问题

项目场景:

在项目中 使用到了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');
	}
}
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值