tag.nvue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <view class="container">
  3. <uni-card is-full>
  4. <text class="uni-h6">标签组件多用于商品分类、重点内容显示等场景。</text>
  5. </uni-card>
  6. <uni-section title="实心标签" type="line" padding>
  7. <view class="example-body">
  8. <view class="tag-view">
  9. <uni-tag text="标签" type="primary" />
  10. </view>
  11. <view class="tag-view">
  12. <uni-tag text="标签" type="success" />
  13. </view>
  14. <view class="tag-view">
  15. <uni-tag text="标签" type="warning" />
  16. </view>
  17. <view class="tag-view">
  18. <uni-tag text="标签" type="error" />
  19. </view>
  20. <view class="tag-view">
  21. <uni-tag text="标签" />
  22. </view>
  23. </view>
  24. </uni-section>
  25. <uni-section title="空心标签" subTitle="使用 inverted 属性显示空心表签" type="line" padding>
  26. <view class="example-body">
  27. <view class="tag-view">
  28. <uni-tag :inverted="true" text="标签" type="primary" />
  29. </view>
  30. <view class="tag-view">
  31. <uni-tag :inverted="true" text="标签" type="success" />
  32. </view>
  33. <view class="tag-view">
  34. <uni-tag :inverted="true" text="标签" type="warning" />
  35. </view>
  36. <view class="tag-view">
  37. <uni-tag :inverted="true" text="标签" type="error" />
  38. </view>
  39. <view class="tag-view">
  40. <uni-tag :inverted="true" text="标签" />
  41. </view>
  42. </view>
  43. </uni-section>
  44. <uni-section title="标签尺寸" subTitle="使用 size 属性控制标签大小" type="line" padding>
  45. <view class="example-body">
  46. <view class="tag-view">
  47. <uni-tag text="标签" type="primary" size="normal" />
  48. </view>
  49. <view class="tag-view">
  50. <uni-tag text="标签" type="primary" size="small" />
  51. </view>
  52. <view class="tag-view">
  53. <uni-tag text="标签" type="primary" size="mini" />
  54. </view>
  55. </view>
  56. </uni-section>
  57. <uni-section title="圆角样式" subTitle="使用 circle 属性控制标签圆角" type="line" padding>
  58. <view class="example-body">
  59. <view class="tag-view">
  60. <uni-tag :circle="true" text="标签" type="primary" />
  61. </view>
  62. <view class="tag-view">
  63. <uni-tag :circle="true" text="标签" type="primary" size="small" />
  64. </view>
  65. <view class="tag-view">
  66. <uni-tag :circle="true" text="标签" type="primary" size="mini" />
  67. </view>
  68. </view>
  69. </uni-section>
  70. <uni-section title="标记样式" subTitle="使用 mark 属性显示标记样式" type="line" padding>
  71. <view class="example-body">
  72. <view class="tag-view">
  73. <uni-tag :mark="true" text="标签" type="primary" size="default" />
  74. </view>
  75. <view class="tag-view">
  76. <uni-tag :mark="true" text="标签" type="primary" size="small" />
  77. </view>
  78. <view class="tag-view">
  79. <uni-tag :mark="true" text="标签" type="primary" size="mini" />
  80. </view>
  81. </view>
  82. </uni-section>
  83. <uni-section title="不可点击状态" subTitle="使用 disabled 属性 显示禁用样式" type="line" padding>
  84. <view class="example-body">
  85. <view class="tag-view">
  86. <uni-tag disabled text="标签" type="primary" />
  87. </view>
  88. </view>
  89. </uni-section>
  90. <uni-section title="自定义样式" subTitle="使用 custom-style 属性自定义样式" type="line" padding>
  91. <view class="example-body">
  92. <view class="tag-view">
  93. <uni-tag text="自定义标签样式"
  94. custom-style="background-color: #4335d6; border-color: #4335d6; color: #fff;">
  95. </uni-tag>
  96. </view>
  97. </view>
  98. </uni-section>
  99. <uni-section title="点击事件" type="line" padding>
  100. <view class="example-body">
  101. <view class="tag-view">
  102. <uni-tag :type="type" text="标签" @click="setType" />
  103. </view>
  104. <view class="tag-view">
  105. <uni-tag :circle="true" :inverted="inverted" text="标签" type="primary" @click="setInverted" />
  106. </view>
  107. </view>
  108. </uni-section>
  109. </view>
  110. </template>
  111. <script>
  112. export default {
  113. components: {},
  114. data() {
  115. return {
  116. type: "default",
  117. inverted: false,
  118. };
  119. },
  120. methods: {
  121. setType() {
  122. let types = ["default", "primary", "success", "warning", "error"];
  123. let index = types.indexOf(this.type);
  124. types.splice(index, 1);
  125. let randomIndex = Math.floor(Math.random() * 4);
  126. this.type = types[randomIndex];
  127. },
  128. setInverted() {
  129. this.inverted = !this.inverted;
  130. },
  131. },
  132. };
  133. </script>
  134. <style lang="scss">
  135. .example-body {
  136. /* #ifndef APP-PLUS-NVUE */
  137. display: flex;
  138. /* #endif */
  139. flex-direction: row;
  140. justify-content: flex-start;
  141. align-items: flex-end;
  142. flex-wrap: wrap;
  143. }
  144. .tag-view {
  145. margin-right: 10px;
  146. }
  147. </style>