index.vue 802 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. <!-- SvgIcon.vue -->
  2. <template>
  3. <svg
  4. class="svg-icon"
  5. :style="{
  6. width: size ? (typeof size === 'number' ? `${size}px` : size) : '1em',
  7. height: size ? (typeof size === 'number' ? `${size}px` : size) : '1em',
  8. color: color,
  9. }"
  10. aria-hidden="true"
  11. >
  12. <use :href="'#' + name"></use>
  13. </svg>
  14. </template>
  15. <script setup>
  16. import { defineProps } from 'vue';
  17. const props = defineProps({
  18. name: {
  19. type: String,
  20. required: true,
  21. },
  22. size: {
  23. type: [String, Number],
  24. default: '1em',
  25. },
  26. color: {
  27. type: String,
  28. default: "currentColor", // 使用 currentColor 继承父级颜色
  29. },
  30. });
  31. </script>
  32. <style scoped>
  33. .svg-icon {
  34. vertical-align: -0.15em;
  35. fill: currentColor;
  36. overflow: hidden;
  37. }
  38. </style>