1、安装包
# NPM
npm install @element-plus/icons-vue
# Yarn
yarn add @element-plus/icons-vue
2、全局注册
import { createApp } from 'vue';
import ElementPlus from 'element-plus';
import 'element-plus/dist/index.css';
import * as ELIcons from '@element-plus/icons-vue';
import App from './App.vue';
const app = createApp(App);
for (const name in ELIcons) {
app.component(name, (ELIcons as any)[name]);
}
app.use(ElementPlus).mount('#app');
3、在组件中使用
<el-icon :size="20">
<edit />
</el-icon>
<el-button type="primary" :icon="Edit"></el-button>
4、动态路由菜单图标
export const constantRoutes: Array<RouteRecordRaw> = [
{
path: '/',
component: layout,
redirect: '/home',
meta: {
title: '首页',
icon: 'home-filled',
},
children: [
{
path: '/home',
name: '首页',
component: () => import( '@/views/home.vue'),
},
],
},
]
<el-menu-item :key="item.path" :index="item.path" :route="item.path">
<el-icon>
<component :is="item.meta.icon" />
</el-icon>
<template #title>{{ item.meta.title }}</template>
</el-menu-item>