在使用xlsx.js导入文件报错Error: Cannot read properties of undefined (reading ‘read‘) at FileReader.read

在项目中想要实现一个成员导入的功能,可以通过导入excel对应文件批量导入数据,这些功能vue-element-admin直接提供了,直接引用即可

  • 在使用的时候得安装xlsx包npm install xlsx
  • 引用import XLSX from 'xlsx'
  • 之后就是报错
    Error: Cannot read properties of undefined (reading 'read') at FileReader.read
    在这里插入图片描述
    同时终端也"export 'default' (imported as 'XLSX') was not found in 'xlsx'
    在这里插入图片描述

这时候可以正常访问,但是当导入excel文件得时候就会报上面错误

  • 解决:直接将import XLSX from 'xlsx'改为import * as XLSX from 'xlsx/xlsx.mjs'即可

猜你喜欢

转载自blog.csdn.net/weixin_47979372/article/details/123984292
今日推荐