zhitong.yu
8 天以前 378d781e6f35f89652aa36e079a8b7fc44cea77e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<template>
  <svg :style="iconStyle" aria-hidden="true">
    <use :xlink:href="symbolId" />
  </svg>
</template>
 
<script setup lang="ts" name="SvgIcon">
import { computed, CSSProperties } from "vue";
 
interface SvgProps {
  name: string; // 图标的名称 ==> 必传
  prefix?: string; // 图标的前缀 ==> 非必传(默认为"icon")
  iconStyle?: CSSProperties; // 图标的样式 ==> 非必传
}
 
const props = withDefaults(defineProps<SvgProps>(), {
  prefix: "icon",
  iconStyle: () => ({ width: "100px", height: "100px" })
});
 
const symbolId = computed(() => `#${props.prefix}-${props.name}`);
</script>