BaseTag.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <template>
  2. <view class="base-tag" :class="{middle: size == 'middle'}" v-if="!imgSrc" :style="[tagStyle]" >{{text}}</view>
  3. <view class="img-tag" :class="{'middle-img-tag': size == 'middle'}" v-else>
  4. <image class="w-full h-full" :src="imgSrc" mode="heightFix"></image>
  5. </view>
  6. </template>
  7. <script>
  8. export default {
  9. name: "tag",
  10. props: {
  11. size: {
  12. // 标签大小 normal, small
  13. type: String,
  14. default: "normal"
  15. },
  16. // 标签内容
  17. text: {
  18. type: String,
  19. default: ""
  20. },
  21. circle: {
  22. type: [Boolean, String],
  23. default: false
  24. },
  25. background: {
  26. type: String,
  27. default: '#e93323'
  28. },
  29. color: {
  30. type: String,
  31. default: '#ffffff'
  32. },
  33. borderColor:{
  34. type: String,
  35. default: ''
  36. },
  37. imgSrc:{
  38. type: String,
  39. default: ''
  40. }
  41. },
  42. computed:{
  43. tagStyle(){
  44. return {
  45. background: this.background,
  46. color: this.color,
  47. border: this.borderColor ? `1rpx solid ${this.borderColor}` : 'none'
  48. }
  49. }
  50. }
  51. };
  52. </script>
  53. <style lang="scss">
  54. .base-tag {
  55. display: flex;
  56. justify-content: center;
  57. align-items: center;
  58. height: 30rpx;
  59. font-size: 18rpx;
  60. padding: 0 8rpx;
  61. color: #333;
  62. border-radius: 4rpx;
  63. background-color: #fff;
  64. margin-right: 8rpx;
  65. box-sizing: border-box;
  66. margin-bottom: 8rpx;
  67. }
  68. .middle{
  69. height: 36rpx;
  70. padding: 0 12rpx;
  71. border-radius: 8rpx;
  72. font-size: 20rpx;
  73. margin-right: 16rpx;
  74. }
  75. .img-tag{
  76. display: block;
  77. height: 30rpx;
  78. border-radius: 4rpx;
  79. margin-right: 8rpx;
  80. box-sizing: border-box;
  81. margin-bottom: 8rpx;
  82. }
  83. .middle-img-tag{
  84. height: 36rpx;
  85. margin-right: 16rpx;
  86. image{
  87. border-radius: 8rpx;
  88. }
  89. }
  90. </style>