vue3导入element-ui 报错Uncaught TypeError: Cannot read property 'prototype' of undefined.
QBug Lifelong Learner

环境

1
2
3
vue --version
@vue/cli 5.0.4
vue 3

问题

今天使用vue3的时候按照某教程按照如下方式导入element-ui

1
2
import Element from 'element-ui'
import "element-ui/lib/theme-chalk/index.css"

结果npm run serve后页面空白,打开Console一看报错了:Uncaught TypeError: Cannot read property 'prototype' of undefined.

解决

搜索了一下发现element-ui是给vue2.x使用的,我们使用vue3需要导入element-plus包,通过需要按照官方文档来进行导入。

官网贴出来的具体导入代码如下:

1
2
3
4
5
6
7
8
9
10
// main.ts
import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import App from './App.vue'

const app = createApp(App)

app.use(ElementPlus)
app.mount('#app')
  • Post title:vue3导入element-ui 报错Uncaught TypeError: Cannot read property 'prototype' of undefined.
  • Post author:QBug
  • Create time:2022-04-01 19:53:54
  • Post link:https://q-bug4.github.io/2022/04/01/vue3导入element-ui-报错Uncaught-TypeError-Cannot-read-property-prototype-of-undefined/
  • Copyright Notice:All articles in this blog are licensed under BY-NC-SA unless stating additionally.