badge.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <template>
  2. <view class="container">
  3. <uni-card is-full :is-shadow="false">
  4. <text class="uni-h6">数字角标通用来标记重点信息使用,如接受到新消息、有未读消息等</text>
  5. </uni-card>
  6. <uni-section title="基础用法" type="line" padding>
  7. <view class="example-body">
  8. <uni-badge class="uni-badge-left-margin" text="1" />
  9. <uni-badge class="uni-badge-left-margin" text="2" type="primary" />
  10. <uni-badge class="uni-badge-left-margin" text="34" type="success" />
  11. <uni-badge class="uni-badge-left-margin" text="45" type="warning" />
  12. <uni-badge class="uni-badge-left-margin" text="123" type="info" />
  13. </view>
  14. </uni-section>
  15. <uni-section title="无底色" type="line" padding>
  16. <view class="example-body">
  17. <uni-badge class="uni-badge-left-margin" :inverted="true" text="1" />
  18. <uni-badge class="uni-badge-left-margin" :inverted="true" text="2" type="primary" />
  19. <uni-badge class="uni-badge-left-margin" :inverted="true" text="34" type="success" />
  20. <uni-badge class="uni-badge-left-margin" :inverted="true" text="45" type="warning" />
  21. <uni-badge class="uni-badge-left-margin" :inverted="true" text="123" type="info" />
  22. </view>
  23. </uni-section>
  24. <uni-section title="自定义样式" type="line" padding>
  25. <view class="example-body">
  26. <uni-badge class="uni-badge-left-margin" text="2" type="primary"
  27. :customStyle="{background: '#4335d6'}" />
  28. <uni-badge class="uni-badge-left-margin" text="2" type="primary" :customStyle="customStyle" />
  29. </view>
  30. </uni-section>
  31. <uni-section title="定位: aboslute 属性" subTitle="注:在安卓端不支持 nvue" type="line" padding>
  32. <uni-badge class="uni-badge-left-margin" :text="value" absolute="rightTop" size="small">
  33. <view class="box"><text class="box-text">右上</text></view>
  34. </uni-badge>
  35. </uni-section>
  36. <uni-section title="偏移: offset 属性(存在 aboslute)" type="line" padding>
  37. <uni-badge class="uni-badge-left-margin" :text="8" absolute="rightTop" :offset="[-3, -3]" size="small">
  38. <view class="box"><text class="box-text">右上</text></view>
  39. </uni-badge>
  40. </uni-section>
  41. <uni-section title="仅显示点: is-dot 属性" type="line" padding>
  42. <uni-badge class="uni-badge-left-margin" :is-dot="true" :text="value" absolute="rightTop" size="small">
  43. <view class="box"><text class="box-text">圆点</text></view>
  44. </uni-badge>
  45. </uni-section>
  46. </view>
  47. </template>
  48. <script>
  49. export default {
  50. components: {},
  51. data() {
  52. return {
  53. value: 0,
  54. customStyle: {
  55. backgroundColor: '#62ed0d',
  56. color: '#fff'
  57. }
  58. };
  59. },
  60. mounted() {
  61. const timer = setInterval(() => {
  62. if (this.value >= 199) {
  63. clearInterval(timer)
  64. return
  65. }
  66. this.value++
  67. }, 100)
  68. }
  69. };
  70. </script>
  71. <style lang="scss">
  72. /* #ifdef MP-ALIPAY */
  73. .uni-badge {
  74. margin-left: 20rpx;
  75. }
  76. /* #endif */
  77. .example-body {
  78. flex-direction: row;
  79. justify-content: flex-start;
  80. }
  81. .uni-badge-left-margin {
  82. margin-left: 10px;
  83. }
  84. .uni-badge-absolute {
  85. margin-left: 40px;
  86. }
  87. .box {
  88. width: 40px;
  89. height: 40px;
  90. display: flex;
  91. justify-content: center;
  92. align-items: center;
  93. text-align: center;
  94. background-color: #DCDFE6;
  95. color: #fff;
  96. font-size: 12px;
  97. }
  98. .box-text {
  99. text-align: center;
  100. color: #fff;
  101. font-size: 12px;
  102. }
  103. </style>