Solution: vue-cli4 creates a project and imports elementUI, and the browser reports an error Uncaught TypeError: Cannot read property 'prototype' of undefined

Check the elementUI official website and find this sentence:

Using vue-cli@3 We have prepared corresponding Element plugins for the new version of vue-cli, and you can use them to quickly build an Element-based project.

The format introduced by the official website is as follows :

import Vue from 'vue';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import App from './App.vue';

Vue.use(ElementUI);

new Vue({
    
    
  el: '#app',
  render: h => h(App)
});

insert image description here
The picture below is the project I created with the latest vue/cli4.5.6 version. In main.js, you can see that the instance object is createApp

The instance object is inconsistent, of course it cannot be imported !!!

There are two solutions:

  • Uninstall the previous version first
npm uninstall -g @vue/cli
  • Install the specified version (it is also possible to install other versions, but it must be able to support import Vue from 'vue')
npm install -g @vue/cli@3.0.4
  • Recreate the project, reinstall and introduce elementUI

An error may be reported when recreating:
error: ~/.vuerc may be outdated. Please delete it and re-run vue-cli in manual mode
insert image description here
to solve:

insert image description here

Just delete it ~ . ~.

The second solution:

No need to uninstall Vue cli4.5.6, choose Vue version when creating scaffolding project, choose 2.x

Scaffolding 2.0 will not have this problem!

Guess you like

Origin blog.csdn.net/WuqibuHuan/article/details/118221876