赞
踩
实现动态添加element-ui的icon图标,即通过变量动态改变图标
- # NPM
- $ npm install @element-plus/icons
- # Yarn
- $ yarn add @element-plus/icons
- # pnpm
- $ pnpm install @element-plus/icons
- import * as Icons from '@element-plus/icons'
- // 统一注册图标,key: i+图标名字
- export function loadIcon(app) {
- // 注册ElementIcon
- for (const [key, component] of Object.entries(Icons)) {
- app.component(key, component)
- }
- }
- import { createApp } from 'vue'
- import App from './App.vue'
-
- const app = createApp(App)
-
- // 统一注册所有 element-ui 图标
- import { loadIcon } from './utils/icon'
- loadIcon(app)
-
- app.mount('#app')
- <el-icon size="13">
- <component :is="item.icon" />
- </el-icon>
说明:component是vue3中一个用于渲染动态组件或元素的“元组件”。
赞
踩
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。