index.vue 938 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. <template>
  2. <text
  3. :class="['iconfont', iconClass]"
  4. :style="{ color: color, fontSize: size + 'rpx',verticalAlign: 'middle'}"
  5. @click="handleClick"
  6. ></text>
  7. </template>
  8. <script setup>
  9. /**
  10. * 图标组件
  11. * 基于iconfont图标库
  12. */
  13. import { computed } from 'vue';
  14. // 组件属性定义
  15. const props = defineProps({
  16. // 图标名称,对应iconfont中的类名,如'icon-home'
  17. name: {
  18. type: String,
  19. required: true
  20. },
  21. // 图标颜色
  22. color: {
  23. type: String,
  24. default: '#000'
  25. },
  26. // 图标大小,单位rpx
  27. size: {
  28. type: [Number, String],
  29. default: 32
  30. }
  31. });
  32. // 事件
  33. const emit = defineEmits(['click']);
  34. // 计算完整的图标类名
  35. const iconClass = computed(() => {
  36. return props.name;
  37. });
  38. // 点击事件处理
  39. const handleClick = (event) => {
  40. emit('click', event);
  41. };
  42. </script>
  43. <style>
  44. /* 引入iconfont样式 */
  45. @import '../../static/iconfont/iconfont.css';
  46. </style>