u-icon.vue 710 B

123456789101112131415161718192021222324252627282930313233343536
  1. <template>
  2. <image class="u-icon-img" :src="resolvedSrc" :style="{ width: (size??0) + 'px', height: (size??0) + 'px' }"
  3. mode="aspectFit" @click="handleClick" />
  4. </template>
  5. <script lang="uts">
  6. export default {
  7. props: {
  8. name: String,
  9. src: String,
  10. size: Number,
  11. active: Boolean
  12. },
  13. computed: {
  14. resolvedSrc() : string {
  15. if (this.src != null) return this.src;
  16. if (this.name != null) {
  17. const key = (this.active == true ? `${this.name}-active` : this.name) as string;
  18. return `/static/icons/${key}.svg`;
  19. }
  20. return '';
  21. }
  22. },
  23. methods: {
  24. handleClick() {
  25. this.$emit('click');
  26. }
  27. }
  28. };
  29. </script>
  30. <style>
  31. .u-icon-img {
  32. /* display: block; */
  33. }
  34. </style>