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)?,圖標(biāo)由在 Element-UI 版本中的樣式,在Element Plus 中被封裝成了一個(gè)個(gè)組件。
安裝圖標(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é)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
解決VUE-Router 同一頁面第二次進(jìn)入不刷新的問題
這篇文章主要介紹了解決VUE-Router 同一頁面第二次進(jìn)入不刷新的問題,具有很好的參考價(jià)值,希望對大家有所幫助。一起跟隨小編過來看看吧2020-07-07vue按需加載組件webpack require.ensure的方法
本篇文章主要介紹了vue按需加載組件webpack require.ensure的方法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2017-12-12vue3 Vite 進(jìn)階rollup命令行使用詳解
這篇文章主要介紹了vue3 Vite 進(jìn)階rollup命令行使用詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08