1.方式一
代码如下
import { createFromIconfontCN } from '@ant-design/icons-vue';
const IconFont = createFromIconfontCN({
scriptUrl: new URL('./assets/font/iconfont.js', import.meta.url).href
});
app.component('IconFont', IconFont);
使用
<IconFont
type="icon-bi-shaixuan"
></IconFont>
2、方式二
组件形式
<template>
<svg class="svg_icon" aria-hidden="true">
<use :xlink:href="symbolId" :fill="color" />
</svg>
</template>
<script>
import { defineComponent, computed } from 'vue';
export default defineComponent({
name: 'SvgIcon',
props: {
type: {
type: String,
default: ''
},
color: {
type: String,
default: '#333'
}
},
setup(props) {
const symbolId = computed(() => `#icon-bi-${props.type}`);
return { symbolId };
}
});
</script>
<style lang="less">
.svg_icon {
width: 1em;
height: 1em;
}
</style>
注册
import IconSvg from '@/components/iconSvg/index.vue';
app.component('IconSvg', IconSvg);
标签:vue,自定义,iconfont,IconFont,props,import,type
From: https://www.cnblogs.com/songkomei/p/17972851