icon.vue 1003 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <template>
  2. <view :style="[style]">
  3. <u--image :src="imgSrc" :width="imgWidth" :height="imgHeight" @click="clickImg"
  4. :showMenuByLongpress="false"/>
  5. </view>
  6. </template>
  7. <script>
  8. export default {
  9. props: {
  10. img: String,
  11. size: [Number,String],//如果有宽和高,则size失效
  12. width: [Number,String],
  13. height: [Number,String],
  14. color: String,
  15. left: [Number,String],
  16. right: [Number,String],
  17. },
  18. computed: {
  19. imgWidth() {
  20. return parseInt(this.width || this.size) / 2
  21. },
  22. imgHeight() {
  23. return parseInt(this.height || this.size) / 2
  24. },
  25. imgSrc() {
  26. return '/static/images/icon/' + this.img + '.png'
  27. },
  28. style() {
  29. let style = {}
  30. if (this.color) {
  31. style.backgroundColor = this.color
  32. }
  33. if (this.left) {
  34. style.marginLeft = this.left + 'rpx'
  35. }
  36. if (this.right) {
  37. style.marginRight = this.right + 'rpx'
  38. }
  39. return style
  40. },
  41. },
  42. data() {
  43. return {
  44. }
  45. },
  46. methods: {
  47. clickImg() {
  48. this.$emit('click')
  49. },
  50. },
  51. }
  52. </script>
  53. <style>
  54. </style>