报错代码如下:
app.js:160 Uncaught TypeError: Cannot read properties of undefined (reading 'prototype')
at eval (types.js?8ad0:39:1)
at ./node_modules/element-ui/lib/utils/types.js (chunk-vendors.js:834:1)
at __webpack_require__ (app.js:157:33)
at fn (app.js:402:21)
at eval (util.js?40a4:19:1)
at ./node_modules/element-ui/lib/utils/util.js (chunk-vendors.js:845:1)
at __webpack_require__ (app.js:157:33)
at fn (app.js:402:21)
at eval (format.js?5a92:49:1)
at ./node_modules/element-ui/lib/locale/format.js (chunk-vendors.js:501:1)
报错原因:
因为我创建的是VUE3项目,VUE的版本为3.2.13,而element-ui只适用于VUE2项目,经过我查询,element-plus适用于VUE3项目。为了更加充分的证明这个问题,我去创建了一个VUE2项目,版本为2.6.14,是能够引用element-ui。
解决方案
1.先确认自己项目是VUE2项目还是VUE3项目,在package.json文件里面查看,如下图所示。
2.根据VUE版本,执行以下其中一步
A.如果是VUE2项目,安装element-ui,指令如下
npm i element-ui --save
B.如果是VUE3项目,安装element-plus,指令如下
npm i element-plus --save
总结
Vue2项目安装element-ui,VUE3项目安装element-plus。