svg-icon.vue 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <div class='icon-content'>
  3. <text v-if="iconName.length > 1" :class="[iconName[0], iconName[1], 'default-color']" :style="{ color: svgFill, fontSize: svgWidth }" @click="svgClick"></text>
  4. <image v-else-if="iconName.length == 1 && iconName[0].includes('/')" :src="iconName[0]" mode="" :style="{ height: svgHeight, width: svgWidth }" @click="svgClick"></image>
  5. <uni-icons v-else :type="iconName[0]" style="line-height:72rpx;" :color="svgFill" :size="svgWidth" @click="svgClick"></uni-icons>
  6. </div>
  7. </template>
  8. <script>
  9. import UniIcons from '@/components/uni-icons/uni-icons.vue';
  10. export default {
  11. name: 'SvgIcon',
  12. components:{UniIcons},
  13. props: {
  14. type: String,
  15. size: {
  16. type: [String, Number],
  17. default: '48rpx'
  18. },
  19. index: [String, Number],
  20. width: {
  21. type: String
  22. },
  23. height: {
  24. type: String
  25. },
  26. color: {
  27. type: String,
  28. default: '#3c9cff'
  29. },
  30. fill: {
  31. type: String
  32. },
  33. stop: [String, Boolean],
  34. },
  35. data() {
  36. return {
  37. fontFamily: ''
  38. }
  39. },
  40. computed: {
  41. svgWidth() {
  42. return this.width || this.size
  43. },
  44. svgHeight() {
  45. return this.height || this.size
  46. },
  47. svgFill() {
  48. return this.fill || this.color
  49. },
  50. iconName() {
  51. return this.type.split(' ')
  52. }
  53. },
  54. methods: {
  55. svgClick(e) {
  56. this.$emit('svg-click', this.index)
  57. this.$emit('click', this.index)
  58. this.stop && e && e.stopPropagation();
  59. }
  60. },
  61. }
  62. </script>
  63. <style lang="scss" scoped>
  64. .icon-content{
  65. /deep/ .u-icon--right{
  66. flex-direction: column;
  67. }
  68. /deep/ .u-icon__icon{
  69. line-height: 36px !important;
  70. }
  71. }
  72. </style>