vue3+vite+ts引入iconfont
一,iconfont建立项目库;
二,Symbol页复制js文件到assets
三,封装icon
点击查看代码
<template>
<svg :class="svgClass" aria-hidden="true">
<use :xlink:href="iconClassName" :fill="color" />
</svg>
</template>
<script setup lang="ts">
import { computed } from 'vue';
const props = defineProps({
iconName: {
type: String,
required: true
},
className: {
type: String,
default: ''
},
color: {
type: String,
default: '#5c6b77'
}
});
// 图标在 iconfont 中的名字
const iconClassName = computed(() => {
return `#${props.iconName}`;
})
// 给图标添加上类名
const svgClass = computed(() => {
if (props.className) {
return `svg-icon ${props.className}`;
}
return 'svg-icon';
});
</script>
<style scoped>
.svg-icon {
width: 25px;
height: 25px;
position: relative;
fill: currentColor;
vertical-align: -2px;
}
</style>
点击查看代码
import "@renderer/assets/icon"
import SvgIcon from "@renderer/components/icon/Index.vue"
const app = createApp(App)
app.component("SvgIcon", SvgIcon)
浙公网安备 33010602011771号