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 @ 2024-01-18 16:46  SKa-M  阅读(422)  评论(0编辑  收藏  举报