schangxiang@126.com
2025-04-29 27ba504441037666e787ded85b4af2f65be65c17
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import { computed, defineComponent } from 'vue'
export default defineComponent({
  name: '图标',
  props: {
    icon: {
      type: String,
      default: '',
    },
    width: {
      type: Number,
      default: 12,
    },
    height: {
      type: Number,
      default: 12,
    },
  },
  emits: ['click'],
  setup(props, { attrs, slots, emit }) {
    const imgUrl = computed(() => {
      const imgName = props.icon
      return new URL(`../../assets/images/${imgName}.png`, import.meta.url).href
    })
 
    return () => {
      return (
        <img
          onClick={(evt: Event) => emit('click', evt)}
          width={props.width}
          height={props.height}
          src={imgUrl.value}
          {...attrs}
        />
      )
    }
  },
})