Vue安裝Element?Plus全過程
Vue安裝Element Plus
Element UI 是一款基于 Vue 的桌面端組件庫,提供了豐富的PC端組件,簡化了常用組件的封裝,大大降低了開發(fā)難度。
隨著 Vue 版本的更新,Element-UI 2.x 升級到了Element Plus 。
使用 Vue CLI 3 需要安裝 Element Plus,具體方式如下:
npm全局安裝
npm install element-plus --save
打開 package.json 文件可以查看是否安裝成功以及安裝的版本信息:

在main.js文件中引入
import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import App from './App.vue'
const app = createApp(App)
app.use(ElementPlus)
app.mount('#app')基本使用
App.vue
<template>
<div id="app">
<h2>Element-UI 測試</h2>
<el-row class="mb-4">
<el-button>Default</el-button>
<el-button type="primary">Primary</el-button>
<el-button type="success">Success</el-button>
<el-button type="info">Info</el-button>
<el-button type="warning">Warning</el-button>
<el-button type="danger">Danger</el-button>
<el-button>中文</el-button>
</el-row>
<el-row class="mb-4">
<el-button plain>Plain</el-button>
<el-button type="primary" plain>Primary</el-button>
<el-button type="success" plain>Success</el-button>
<el-button type="info" plain>Info</el-button>
<el-button type="warning" plain>Warning</el-button>
<el-button type="danger" plain>Danger</el-button>
</el-row>
<el-row class="mb-4">
<el-button round>Round</el-button>
<el-button type="primary" round>Primary</el-button>
<el-button type="success" round>Success</el-button>
<el-button type="info" round>Info</el-button>
<el-button type="warning" round>Warning</el-button>
<el-button type="danger" round>Danger</el-button>
</el-row>
<el-row>
<el-button :icon="Search" circle />
<el-button type="primary" :icon="Edit" circle />
<el-button type="success" :icon="Check" circle />
<el-button type="info" :icon="Message" circle />
<el-button type="warning" :icon="Star" circle />
<el-button type="danger" :icon="Delete" circle />
</el-row>
</div>
</template>運(yùn)行結(jié)果
如下:

官網(wǎng)版本:

可以看到 icon 圖標(biāo)信息并沒有成功顯示。
這是因?yàn)椋瑘D標(biāo)由在 Element-UI 版本中的樣式,在Element Plus 中被封裝成了一個個組件。
安裝圖標(biāo)庫
npm install @element-plus/icons-vue
然后在main.js中使用for循環(huán)
將圖標(biāo)以組件的形式全部引入:
import { createApp } from 'vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import App from './App.vue'
import * as ElIcon from '@element-plus/icons-vue'
const app = createApp(App)
for (let iconName in ElIcon){
app.component(iconName, ElIcon[iconName])
}
app.use(ElementPlus)
app.mount('#app')需要通過標(biāo)簽的方式使用
<el-icon><Search/></el-icon>
App.vue
<template>
<div id="app">
<h2>Element-UI 測試</h2>
<br>
<!-- 在組件中使用 -->
<el-row>
<el-button circle icon = "Search"></el-button>
<el-button type="primary" circle icon = "Edit"></el-button>
<el-button type="success" circle icon = "Check"></el-button>
<el-button type="info" circle icon = "Message"></el-button>
<el-button type="warning" circle icon = "Star"></el-button>
<el-button type="danger" circle icon = "Delete"></el-button>
</el-row>
<br>
<!-- 結(jié)合 el-icon 使用 -->
<el-row>
<el-icon><Search/></el-icon>
<el-icon><Edit/></el-icon>
<el-icon><Check/></el-icon>
<el-icon><Message/></el-icon>
<el-icon><Star/></el-icon>
<el-icon><Delete/></el-icon>
</el-row>
</div>
</template>效果如下:

總結(jié)
以上為個人經(jīng)驗(yàn),希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
vscode配置@路徑提示方式,并解決vue文件內(nèi)失效的問題
這篇文章主要介紹了vscode配置@路徑提示方式,并解決vue文件內(nèi)失效的問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-10-10
vue中的get方法\post方法如何實(shí)現(xiàn)傳遞數(shù)組參數(shù)
這篇文章主要介紹了vue中的get方法\post方法如何實(shí)現(xiàn)傳遞數(shù)組參數(shù),具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2022-04-04
vuex實(shí)現(xiàn)數(shù)據(jù)持久化的兩種方案
這兩天在做vue項目存儲個人信息的時候,遇到了頁面刷新后個人信息數(shù)據(jù)丟失的問題,在查閱資料后,我得出兩種解決數(shù)據(jù)丟失,使用數(shù)據(jù)持久化的方法,感興趣的小伙伴跟著小編一起來看看吧2023-08-08
Vue監(jiān)聽localstorage變化的方法詳解
在日常開發(fā)中,我們經(jīng)常使用localStorage來存儲一些變量,這些變量會存儲在瀏覽中,對于localStorage來說,即使關(guān)閉瀏覽器,這些變量依然存儲著,方便我們開發(fā)的時候在別的地方使用,本文就給大家介紹Vue如何監(jiān)聽localstorage的變化,需要的朋友可以參考下2023-10-10
el-form-item表單label添加提示圖標(biāo)的實(shí)現(xiàn)
本文主要介紹了el-form-item表單label添加提示圖標(biāo)的實(shí)現(xiàn),我們將了解El-Form-Item的基本概念和用法,及添加提示圖標(biāo)以及如何自定義圖標(biāo)樣式,感興趣的可以了解一下2023-11-11
vue中跳轉(zhuǎn)界面的3種實(shí)現(xiàn)方法
這篇文章主要給大家介紹了關(guān)于vue中跳轉(zhuǎn)界面的3種實(shí)現(xiàn)方法,文中通過實(shí)例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考借鑒價值,需要的朋友可以參考下2023-07-07

