SvgIcon.vue 729 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <template>
  2. <svg :class="svgClass" :aria-hidden="true">
  3. <use :xlink:href="iconName" />
  4. </svg>
  5. </template>
  6. <script setup>
  7. import { computed } from 'vue'
  8. const props = defineProps({
  9. iconClass: {
  10. type: String,
  11. },
  12. icon: {
  13. // iconfont 库
  14. type: String,
  15. },
  16. className: {
  17. type: String,
  18. default: '',
  19. },
  20. })
  21. const iconName = computed(() => {
  22. return props.icon ? `#${props.icon}` : `#icon-${props.iconClass}`
  23. })
  24. const svgClass = computed(() => {
  25. if (props.className) {
  26. return `svg-icon${props.className}`
  27. }
  28. return 'svg-icon'
  29. })
  30. </script>
  31. <style scoped lang="less">
  32. .svg-icon {
  33. width: 1em;
  34. height: 1em;
  35. vertical-align: -0.15em;
  36. fill: currentColor;
  37. overflow: hidden;
  38. }
  39. </style>