vue3 element-plus如何使用icon圖標組件
更新時間:2024年03月19日 14:15:22 作者:天馬3798
這篇文章主要介紹了vue3 element-plus如何使用icon圖標組件問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
vue3 element-plus使用icon圖標組件
目前 element-plus版本是2.0.4
當前版本的icon還沒有默認在組件中,需要另外安裝才能使用圖標。
使用步驟
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>之前的使用方式還在支持中,目前需要特殊導入。
<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.動態(tài)綁定icon/菜單動態(tài)綁定icon
// html <template> <component class="xxx" :is="iconName"></component> </template>
// script
export default {
name: 'Login',
setup() {
const iconName = 'Search'
return {
iconName
}
}
}總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Vite+Vue3項目版本更新檢查與頁面自動刷新的實現(xiàn)方案
使用 Vite 對 Vue 項目進行打包,對 js 和 css 文件使用了 chunkhash 進行了文件緩存控制,但是項目的 index.html 文件在版本頻繁迭代更新時,會存在被瀏覽器緩存的情況,所以本文介紹了Vite+Vue3項目版本更新檢查與頁面自動刷新方案,需要的朋友可以參考下2025-09-09
Vue+elementui 實現(xiàn)復雜表頭和動態(tài)增加列的二維表格功能
這篇文章主要介紹了Vue+elementui 實現(xiàn)復雜表頭和動態(tài)增加列的二維表格功能,本文通過實例代碼給大家介紹的非常詳細,具有一定的參考借鑒價值,需要的朋友可以參考下2019-09-09
vue-drawer-layout實現(xiàn)手勢滑出菜單欄
這篇文章主要為大家詳細介紹了vue-drawer-layout實現(xiàn)手勢滑出菜單欄,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2020-11-11
vue3中template使用ref無需.value原因解析
vue3的template中使用ref變量無需使用.value,還可以在事件處理器中進行賦值操作時,無需使用.value就可以直接修改ref變量的值,這篇文章主要介紹了原來vue3中template使用ref無需.value是因為這個,需要的朋友可以參考下2024-06-06

