Vue與element聯(lián)動踩過的坑
vue最新版本中創(chuàng)建的實例對象是createApp
而我們正常按照官方文檔進行安裝的element-ui,只支持實例對象為Vue
所以問題就出在了這里
如果你的實例對象是Vue的話,
vue create my-app
cd?
my-app
vue add element
然后再在main.js中引入即可
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)
});
如果你的實例對象是
createApp,
我看別的大佬都教你降低版本,讓你卸載,安一個兼容的版本
我就不一樣了直接
用element-plus的方法來引入element-ui就好了嘛
vue create my-app
cd?
my-app
vue add element-plus
npm install vue-cli-plugin-element-plus
在main.js中
import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import 'element-ui/lib/theme-chalk/index.css'
import installElementPlus from './plugins/element'
const app = createApp(App)
installElementPlus(app)
app.use(store).use(router).mount('#app')
下面我以走馬燈(輪播圖示例如何使用)
<template>
<div id="swiper">
?<el-carousel height="300px" id="imgs">
? ?<el-carousel-item ?v-for="(item,index) in banners" :key="index">
? ? ?<a :href="item.link">-->
? ? ? ? ? ?<img :src="item.image" alt="">
? ? ?</a>
? ?</el-carousel-item>
?</el-carousel>
</div>
</template>

好了,散會!