vue+antd-vue(自定义iconfont图标组件)

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);
posted @   SKa-M  阅读(625)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· DeepSeek R1 简明指南:架构、训练、本地部署及硬件要求
· NetPad:一个.NET开源、跨平台的C#编辑器
· 面试官:你是如何进行SQL调优的?
点击右上角即可分享
微信分享提示