index.vue 839 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <!--
  2. * @Author: wjc
  3. * @Date: 2024-07-01 10:05:11
  4. * @LastEditors: wjc
  5. * @LastEditTime: 2024-07-11 11:49:28
  6. * @Description: 仅支持 H5
  7. -->
  8. <template>
  9. <svg v-bind="$attrs" aria-hidden="true" class="m-icon">
  10. <use :xlink:href="symbolId" :fill="color" />
  11. </svg>
  12. </template>
  13. <script setup lang="ts">
  14. defineOptions({
  15. name: 'MIcon',
  16. })
  17. const props = withDefaults(
  18. defineProps<{
  19. prefix?: string
  20. name: string
  21. color?: string
  22. size?: number | string
  23. }>(),
  24. {
  25. prefix: 'icon',
  26. name: '',
  27. color: '#333',
  28. size: 24,
  29. }
  30. )
  31. const symbolId = computed(() => `#${props.prefix}-${props.name}`)
  32. const sizeStyle = computed(() => `${props.size}px`)
  33. </script>
  34. <style scoped lang="scss">
  35. .m-icon {
  36. width: v-bind(sizeStyle);
  37. height: v-bind(sizeStyle);
  38. }
  39. </style>