Index.vue 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <template>
  2. <svg class="iconfont-svg" :style="iconStyle" aria-hidden="true">
  3. <use :xlink:href="icon" />
  4. </svg>
  5. </template>
  6. <script setup lang="ts">
  7. import { computed } from 'vue';
  8. const props = defineProps({
  9. icon: {
  10. type: String,
  11. default: '',
  12. },
  13. style: {
  14. type: String,
  15. default: '',
  16. },
  17. fontSize: {
  18. type: String,
  19. default: '',
  20. },
  21. fillColor: {
  22. type: String,
  23. default: 'currentColor',
  24. },
  25. });
  26. const iconStyle = computed(() => {
  27. let style = props.style ? props.style : '';
  28. let fontSizeStyle = props.fontSize ? 'font-size:' + props.fontSize + 'px;' : '';
  29. let fillStyle = props.fillColor ? 'fill:' + props.fillColor + ';' : '';
  30. return style + fillStyle + fontSizeStyle;
  31. });
  32. const icon = computed(() => {
  33. return props.icon ? '#icon-' + props.icon : '';
  34. });
  35. </script>
  36. <style scoped>
  37. .iconfont-svg {
  38. width: 1em;
  39. height: 1em;
  40. vertical-align: -0.15em;
  41. fill: currentcolor;
  42. overflow: hidden;
  43. }
  44. </style>