Bang Hu
1 天以前 8a709ba6db50831048f9c3e2452ea6dc6c3de36f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<!--
 * @Description: 
 * @Version: 2.0
 * @Autor: wuyun
 * @Date: 2023-06-09 09:50:40
 * @LastEditors: wuyun
 * @LastEditTime: 2023-06-15 14:36:35
-->
<template>
  <svg :class="svgClass" v-bind="$attrs" :style="iconStyle">
    <use :href="iconName" rel="external nofollow" />
  </svg>
</template>
<script setup lang="ts">
import { computed, CSSProperties } from 'vue';
interface Props {
  name: string;
  size?: string;
  color: string;
}
 
const props = withDefaults(defineProps<Props>(), {
  name: '',
  size: '18px',
  color: '#007CEE',
});
const  {name,size,color}=toRefs(props)
const iconStyle = computed((): CSSProperties => {
  return {
    color:color.value || '#007CEE',
    fontSize:size.value || '20px',
    fill: color.value || '#007CEE' , 
    stroke: color.value 
  };
});
const iconName = computed(() => `#icon-${name.value}`)
const svgClass = computed(() => {
  if (name.value) {
     return `svg-icon ${iconName.value}`
  }
  return "svg-icon"
})
</script>
<style scoped>
.svg-icon {
  width: 1em;
  height: 1em;
  fill: 'currentColor';
  vertical-align: middle;
}
</style>