Element Plus官网 https://www.yuque.com/wl001/oqbgmh/vz0wio#PeCY8

1、element-plus SVG Icon 注册方法

安装element-plus SVG图标库

  1. # NPM
  2. $ npm install @element-plus/icons-vue
  3. # Yarn
  4. $ yarn add @element-plus/icons-vue
  5. # pnpm
  6. $ pnpm install @element-plus/icons-vue

main.js全局使用

  1. import ElementPlus from 'element-plus'
  2. import zhCn from 'element-plus/es/locale/lang/zh-cn'
  3. import * as ElIcons from '@element-plus/icons-vue'
  4. import 'element-plus/dist/index.css'
  5. var app = createApp(App);
  6. for(const name in ElIcons){
  7. /*
  8. * elIcon为前缀的命名规则,是为了适配已经使用属性名添加图标的内置组件,
  9. * 例如:<el-button icon="el-icon-refresh"></el-button>
  10. * 单独name app.component(name,ElIcons[name]); 案例<edit></edit>就不需要在单独引入了
  11. * 例如:<el-button icon="refresh"></el-button>
  12. */
  13. app.component('elIcon'+ name,ElIcons[name]);
  14. }
  15. /* ElementPlus默认是英语 需要选择默认语言 */
  16. app.use(ElementPlus,{size: 'mini',locale: zhCn});
  17. app.mount('#app');

案例

  1. <template>
  2. <!-- main.js全局引入svg icon -->
  3. <el-button icon="el-icon-refresh"></el-button>
  4. <div>
  5. <!-- import单独引入svg icon -->
  6. <el-icon :size="size" :color="color">
  7. <edit></edit>
  8. </el-icon>
  9. <edit></edit>
  10. <!-- main.js全局引入svg icon -->
  11. <el-icon-edit></el-icon-edit>
  12. </div>
  13. </template>
  14. <script>
  15. import { Edit } from '@element-plus/icons-vue'
  16. export default {
  17. name: "firstPage",
  18. components:{
  19. Edit
  20. },
  21. setup(){
  22. return{
  23. }
  24. }
  25. }
  26. </script>