今天遇到一个问题,在创建Vue项目之后在按照官方文档的步骤导入element UI的时候总是出现报错,内容大致如下:
F: \Project\Sushiju\sushiju>npm i element-ui -S
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unabLe to resolve dependency tree
npm ERR!
npm ERR! While resolving: sushiju@0.1.0
npm ERR! Found: vue@3.0.5
npm ERR! node_ modules/vue
npm ERR!
vUe@"A3.0.0" from the root project
npm ERR !
npm ERR! CouLd not resolve dependency:
npm ERR! peer vueQ"^2.5.17" from eLement-ui@2.15.0
npm ERR! node modules/element-ui
npm ERR!
eLement-ui@"*" from the root project
经过排查,这是npm和element ui版本不对应导致的版本依赖冲突的问题。把npm的版本由8降到6.14就好了
npm install -g npm@6.14.8
修改npm版本之后用下面的命令来下载elementUI
npm install --save element-plus
?之后在main.js里面加入下面的内容
import { createApp } from 'vue'
import App from './views/home/index.vue'
import './registerServiceWorker'
import router from './router'
import store from './store'
import elementPlus from 'element-plus'
//这里看实际的项目文件
import 'element-plus/theme-chalk/index.css'
createApp.use(elementPlus)
createApp(App).use(store).use(router).mount('#app')
到了这里不出意外的话应该已经出意外了,比如刷新不出页面,就是个空白页。那么直接按照下面的内容来修改就好了。
import { createApp } from 'vue'
import App from './views/home/index.vue'
import './registerServiceWorker'
import router from './router'
import store from './store'
import elementPlus from 'element-plus'
//按照实际的项目文件
import 'element-plus/theme-chalk/index.css'
createApp(App).use(store).use(router).use(elementPlus).mount('#app')
|