在vue3 + ElementUI 项目中自定义 Icon

前言:

在 iconfont阿里巴巴矢量图标库 中复制 svg 代码,封装成一个组件。

正文:

javascript 复制代码
<template>
    <svg :style="{ width: sizeCss, height: sizeCss, color: color, display: 'inline-block', verticalAlign: 'middle',marginRight: '4px' }"
        viewBox="0 0 1024 1024" aria-hidden="true" focusable="false">
        <path
            d="M637.155556 455.111111c-20.48 0-34.133333 13.653333-34.133334 34.133333 0 75.093333-61.44 136.533333-136.533333 136.533334H261.688889c-75.093333 0-136.533333-61.44-136.533333-136.533334 0-75.093333 61.44-136.533333 136.533333-136.533333h102.4c20.48 0 34.133333-13.653333 34.133333-34.133333S384.568889 284.444444 364.088889 284.444444H261.688889C145.635556 284.444444 56.888889 373.191111 56.888889 489.244444s88.746667 204.8 204.8 204.8h204.8c116.053333 0 204.8-88.746667 204.8-204.8 0-20.48-13.653333-34.133333-34.133333-34.133333z"
            fill="currentColor"
            p-id="31867"></path>
        <path
            d="M807.822222 284.444444h-204.8C486.968889 284.444444 398.222222 373.191111 398.222222 489.244444c0 20.48 13.653333 34.133333 34.133334 34.133334s34.133333-13.653333 34.133333-34.133334c0-75.093333 61.44-136.533333 136.533333-136.533333h204.8c75.093333 0 136.533333 61.44 136.533334 136.533333 0 75.093333-61.44 136.533333-136.533334 136.533334h-102.4c-20.48 0-34.133333 13.653333-34.133333 34.133333s13.653333 34.133333 34.133333 34.133333h102.4c116.053333 0 204.8-88.746667 204.8-204.8S923.875556 284.444444 807.822222 284.444444z"
            fill="currentColor"
            p-id="31868">
        </path>
    </svg>
</template>

<script setup>
import { computed } from 'vue'

const props = defineProps({
  size: { type: [Number, String], default: 20 },
  color: { type: String, default: 'currentColor' },
})

const sizeCss = computed(() => (typeof props.size === 'number' ? `${props.size}px` : props.size))
const color = computed(() => props.color)
</script>

然后在其他组件中使用:

相关推荐
|晴 天|20 小时前
Vue 3 + TypeScript + Element Plus 博客系统开发总结与思考
前端·vue.js·typescript
猫32821 小时前
v-cloak
前端·javascript·vue.js
旷世奇才李先生21 小时前
Vue 3\+Vite\+Pinia实战:企业级前端项目架构设计
前端·javascript·vue.js
SoaringHeart1 天前
Flutter进阶:用OverlayEntry 实现所有弹窗效果
前端·flutter
IT_陈寒1 天前
Vite静态资源加载把我坑惨了
前端·人工智能·后端
herinspace1 天前
管家婆实用贴-如何分离和附加数据库
开发语言·前端·javascript·数据库·语音识别
小码哥_常1 天前
从MVC到MVI:一文吃透架构模式进化史
前端
嗷o嗷o1 天前
Android BLE 的 notify 和 indicate 到底有什么区别
前端
豹哥学前端1 天前
别再背“var 提升,let/const 不提升”了:揭开暂时性死区的真实面目
前端·面试
lar_slw1 天前
k8s部署前端项目
前端·容器·kubernetes