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')

重启即可

相关推荐
chxii24 分钟前
在 IIS 中实现 SSL 证书的自动续期
前端
周星星日记31 分钟前
vue3中静态提升和patchflag实现
前端·vue.js·面试
橘子编程37 分钟前
React 19 全栈开发实战指南
前端·react.js·前端框架
DanCheOo38 分钟前
AI Streaming 架构:从浏览器到服务端的全链路流式设计
前端·agent
我是小趴菜44 分钟前
前端如何让图片、视频、pdf等文件在浏览器直接下载而非预览
前端
cg331 小时前
开源项目自动化:用 GitHub Actions 让每个 Issue 都被温柔以待
前端
haierccc1 小时前
Win7、2008R2、Win10、Win11使用FLASH的方法
前端·javascript·html
We་ct1 小时前
LeetCode 50. Pow(x, n):从暴力法到快速幂的优化之路
开发语言·前端·javascript·算法·leetcode·typescript·
柠檬味的Cat1 小时前
使用腾讯云COS作为WordPress图床的实践
前端·github·腾讯云
Hilaku1 小时前
卷AI、卷算法、2026 年的前端工程师到底在卷什么?
前端·javascript·面试