index.vue 618 B

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