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)
});
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
to solve:
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!