element-plus SVG Icon 注册方法 @element-plusicons vue3 main.js统一导入及注册el-icon组件

安装element-plus SVG图标库

npm install @element-plus/icons

Main.js

import ElementPlus from 'element-plus';
import * as ElIcons from '@element-plus/icons';

// 此处省略若干业务代码

const app = createApp(App);
for(const name in ElIcons){
  /*
   * 以elIcon为前缀的命名规则,是为了适配已经使用属性名添加图标的内置组件,
   * 例如:<el-button icon="el-icon-refresh"></el-button>
   */
  app.component('elIcon' + name, ElIcons[name]);
}
app.use(ElementPlus, { size: 'mini', zIndex: 2000 });
app.mount('#app');

此时已经完成所有内置组件的图标迁移工作,自定义标签需要或class名引用的图标需要手动完成迁移。

图标使用方法请参阅Element Plus Icon 图标


版权声明:本文为web18484626332原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。