element-plus 在vue3 中不生效的原因解決方法(element-plus引入)
vue3.0 不兼容 element-ui ,于是推出了element-plus
1.安裝element-plus (3種方式 )
npm install element-plus --save (推薦)
yarn add element-plus
pnpm install element-plus
2. 在main.js種引用
import 'element-plus/theme-chalk/index.css' //默認css樣式 英文 import Element from 'element-plus' //引入插件 import zhCn from 'element-plus/es/locale/lang/zh-cn' //引入中文包 //全局 使用element-plus //中文使用 createApp(App).use(Element,{locale:zhCn}).mount('#app') //默認英文使用 createApp(App).use(Element).mount('#app')
引入最重要看官方引入方法
官方引入方法:
https://element-plus.org/es-ES/guide/quickstart.html#configuracion-global
正常引入不生效的原因如下
原因一
main.js中加載順序不對
import { createApp } from 'vue' import App from './App.vue' import router from './router' import ElementPlus from 'element-plus'; import 'element-plus/lib/theme-chalk/index.css'; const app = createApp(App) app.use(ElementPlus) app.use(router).mount('#app')
原因二
<el-tree ref="elTreeRef" :data="menus" show-checkbox node-key="id" :props="{ children: 'children', label: 'name' }" @check="handleCheckChange" > import { ElTree } from 'element-plus' const elTreeRef = ref<InstanceType<typeof ElTree>>() const editCallback = (item: any) => { const leafKeys = menuMapLeafKeys(item.menuList) nextTick(() => { console.log(elTreeRef.value) elTreeRef.value?.setCheckedKeys(leafKeys, false) }) }
有的時候全局注冊,但是不生效的原因,只能在template中可以使用,在js邏輯中使用組件名稱方法還是需要單獨引入的
到此這篇關(guān)于element-plus 在vue3 中不生效的原因解決方法(element-plus引入)的文章就介紹到這了,更多相關(guān)element-plus vue3 不生效內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
vue實現(xiàn)過渡動畫Message消息提示組件示例詳解
這篇文章主要為大家介紹了vue實現(xiàn)過渡動畫Message消息提示組件示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-07-07Windows系統(tǒng)下使用nginx部署vue2項目的全過程
nginx是一個高性能的HTTP和反向代理服務(wù)器,因此常用來做靜態(tài)資源服務(wù)器和后端的反向代理服務(wù)器,下面這篇文章主要給大家介紹了關(guān)于Windows系統(tǒng)下使用nginx部署vue2項目的相關(guān)資料,需要的朋友可以參考下2023-03-03Vue2實現(xiàn)圖片的拖拽,縮放和旋轉(zhuǎn)效果的示例代碼
這篇文章主要為大家介紹了如何基于vue2?實現(xiàn)圖片的拖拽、旋轉(zhuǎn)、鼠標滾動放大縮小等功能。文中的示例代碼講解詳細,感興趣的小伙伴可以嘗試一下2022-11-11vue在取對象長度length時候出現(xiàn)undefined的解決
這篇文章主要介紹了vue在取對象長度length時候出現(xiàn)undefined的解決方案,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-06-06