main.ts
import SvgIcon from '@/components/SvgIcon'
import elementIcons from '@/components/SvgIcon/'
app.use(elementIcons)
app.component('svg-icon', SvgIcon)
SvgIcon.ts
import * as components from '@element-plus/icons-vue'
export default {
install: (app) => {
// 官网的方式
// for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
// app.component(key, component)
// }
for (const key in components) {
const componentConfig = components[key];
app.component(componentConfig.name, componentConfig);
}
},
};
模板
<el-icon><Service /></el-icon>