badge.vue 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <template>
  2. <view>
  3. <view v-if="propNumber != 0" class="am-badge">
  4. <view :class="'am-badge-text ' + ((propNumber > 99) ? 'am-badge-text-max' : '')">
  5. <text>{{(propNumber > 99) ? '99+' : propNumber}}</text>
  6. </view>
  7. </view>
  8. </view>
  9. </template>
  10. <script>
  11. export default {
  12. data() {
  13. return {};
  14. },
  15. components: {},
  16. props: {
  17. propNumber: {
  18. type: [Number,String],
  19. default: 0
  20. }
  21. },
  22. methods: {}
  23. };
  24. </script>
  25. <style>
  26. .am-badge {
  27. display: inline-block;
  28. position: relative;
  29. vertical-align: middle;
  30. }
  31. .am-badge-text {
  32. display: inline-block;
  33. position: absolute;
  34. right: 0;
  35. transform: translate(50%, -50%);
  36. top: 0px;
  37. min-width: 14px;
  38. padding: 0;
  39. height: 14px;
  40. line-height: 14px;
  41. text-align: center;
  42. background-color: #FF3B30;
  43. border-radius: 20px;
  44. color: #fff;
  45. font-size: 10px;
  46. padding: 1px 1px;
  47. box-shadow: 0 0 5px rgb(0 0 0 / 60%);
  48. }
  49. .am-badge-text-max {
  50. padding: 1px 2px;
  51. }
  52. </style>