BaseTag.vue 1.6 KB

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