vue3 element-plus如何使用icon圖標(biāo)組件
vue3 element-plus使用icon圖標(biāo)組件
目前 element-plus版本是2.0.4
當(dāng)前版本的icon還沒有默認(rèn)在組件中,需要另外安裝才能使用圖標(biāo)。
使用步驟
1.安裝@element-plus/icons-vue庫
npm install @element-plus/icons-vue
2.全局引入icon組件
import { createApp } from 'vue' import App from './App.vue' import installElementPlus from './plugins/element' //main.js import * as ElIconModules from '@element-plus/icons-vue' var app=createApp(App); app.use(installElementPlus); Object.keys(ElIconModules).forEach(function (key) { app.component(ElIconModules[key].name, ElIconModules[key]) }) app.mount('#app');
3.使用icon
<edit style="width: 1em; height: 1em; margin-right: 8px;" /> <share style="width: 1em; height: 1em; margin-right: 8px;" /> <delete style="width: 1em; height: 1em; margin-right: 8px;" /> <search style="width: 1em; height: 1em; margin-right: 8px;" />
<el-button type="primary"> <el-icon style="vertical-align: middle;"> <search /> </el-icon> <span style="vertical-align: middle;"> Search </span> </el-button>
之前的使用方式還在支持中,目前需要特殊導(dǎo)入。
<template> <div class="flex"> <el-button type="primary" :icon="Edit"></el-button> <el-button type="primary" :icon="Share"></el-button> <el-button type="primary" :icon="Delete"></el-button> <el-button type="primary" :icon="Search">Search</el-button> <el-button type="primary"> Upload<el-icon class="el-icon--right"><Upload /></el-icon> </el-button> </div> </template> <script setup lang="ts"> import { Edit, Share, Delete, Search, Upload } from '@element-plus/icons-vue' </script>
4.動(dòng)態(tài)綁定icon/菜單動(dòng)態(tài)綁定icon
// html <template> <component class="xxx" :is="iconName"></component> </template>
// script export default { name: 'Login', setup() { const iconName = 'Search' return { iconName } } }
總結(jié)
以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
解決vue使用vant輪播組件swipe + flex時(shí)文字抖動(dòng)問題
這篇文章主要介紹了解決vue使用vant輪播組件swipe + flex時(shí)文字抖動(dòng)問題,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友參考下吧2021-01-01vue中$set的使用(結(jié)合在實(shí)際應(yīng)用中遇到的坑)
這篇文章主要介紹了vue中$set的使用(結(jié)合在實(shí)際應(yīng)用中遇到的坑),小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧2018-07-07vue組件表單數(shù)據(jù)回顯驗(yàn)證及提交的實(shí)例代碼
今天小編就為大家分享一篇vue組件表單數(shù)據(jù)回顯驗(yàn)證及提交的實(shí)例代碼,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧2018-08-08vue element 生成無線級(jí)左側(cè)菜單的實(shí)現(xiàn)代碼
這篇文章主要介紹了vue element 生成無線級(jí)左側(cè)菜單的實(shí)現(xiàn)代碼,代碼簡單易懂,非常不錯(cuò),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-08-08vue中使用element組件時(shí)事件想要傳遞其他參數(shù)的問題
這篇文章主要介紹了vue中使用element組件時(shí)事件想要傳遞其他參數(shù)的問題,本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-09-09使用Mockjs模擬接口實(shí)現(xiàn)增刪改查、分頁及多條件查詢
Mock.js是一個(gè)模擬數(shù)據(jù)生成器,可以讓前端獨(dú)立于后端進(jìn)行開發(fā),下面這篇文章主要給大家介紹了關(guān)于使用Mockjs模擬接口實(shí)現(xiàn)增刪改查、分頁及多條件查詢的相關(guān)資料,需要的朋友可以參考下2022-04-04解決微信瀏覽器緩存站點(diǎn)入口文件(IIS部署Vue項(xiàng)目)
這篇文章主要介紹了解決微信瀏覽器緩存站點(diǎn)入口文件(IIS部署Vue項(xiàng)目),本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-06-06