Element-Plus-全局自动引入图标组件,无需每次import

效果图

配置如下

1、核心代码修改main.js/ts

javascript 复制代码
//main.js
// 全局注册图标组件
import * as ElementPlusIconsVue from '@element-plus/icons-vue'
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
app.use(ElementPlusIconsVue)

2、完整代码

javascript 复制代码
import './assets/main.css'

import { createApp } from 'vue'
import App from './App.vue'
// 全局注册图标组件
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

// app声明
const app = createApp(App);
//核心代码
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
// use
app.use(ElementPlusIconsVue)
// mount
app.mount('#app')

重启即可

相关推荐
慧一居士5 分钟前
flex 布局完整功能介绍和示例演示
前端
DoraBigHead7 分钟前
小哆啦解题记——两数失踪事件
前端·算法·面试
一斤代码6 小时前
vue3 下载图片(标签内容可转图)
前端·javascript·vue
中微子6 小时前
React Router 源码深度剖析解决面试中的深层次问题
前端·react.js
光影少年6 小时前
从前端转go开发的学习路线
前端·学习·golang
中微子6 小时前
React Router 面试指南:从基础到实战
前端·react.js·前端框架
3Katrina6 小时前
深入理解 useLayoutEffect:解决 UI "闪烁"问题的利器
前端·javascript·面试
前端_学习之路7 小时前
React--Fiber 架构
前端·react.js·架构
coderlin_7 小时前
BI布局拖拽 (1) 深入react-gird-layout源码
android·javascript·react.js
伍哥的传说7 小时前
React 实现五子棋人机对战小游戏
前端·javascript·react.js·前端框架·node.js·ecmascript·js