index.vue 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <view class="m-badge-box">
  3. <text class="m-badge">{{getValue}}</text>
  4. </view>
  5. </template>
  6. <script>
  7. export default {
  8. // 选项上数量标签
  9. name: "m-badge",
  10. props: {
  11. value: {
  12. type: [String, Number],
  13. default: 0,
  14. },
  15. },
  16. computed: {
  17. getValue(){
  18. return Number(this.value) > Number(this.max) ? this.max + "+" : this.value
  19. }
  20. },
  21. data() {
  22. return {
  23. max:99
  24. };
  25. }
  26. }
  27. </script>
  28. <style lang="scss" scoped>
  29. .m-badge-box {
  30. display: flex;
  31. flex-direction: column;
  32. justify-content: center;
  33. align-items: center;
  34. position: absolute;
  35. top: 0rpx;
  36. box-sizing: border-box;
  37. right: 60rpx;
  38. background: #FF2923;
  39. border: 4rpx solid white;
  40. border-radius: 30rpx;
  41. }
  42. .m-badge {
  43. font-family: 'PingFang SC';
  44. font-style: normal;
  45. font-size: 24rpx;
  46. max-width: 60rpx;
  47. min-width: 30rpx;
  48. height: 30rpx;
  49. padding: 0 8rpx;
  50. font-weight: 500;
  51. display: flex;
  52. flex-direction: row;
  53. justify-content: center;
  54. align-items: center;
  55. text-align: center;
  56. color: white;
  57. // text-overflow: -o-ellipsis-lastline;
  58. // overflow: hidden; //溢出内容隐藏
  59. // text-overflow: ellipsis; //文本溢出部分用省略号表示
  60. // display: -webkit-box; //特别显示模式
  61. // -webkit-line-clamp: 1; //行数
  62. // line-clamp: 1;
  63. // -webkit-box-orient: vertical; //盒子中内容竖直排列
  64. white-space: nowrap;
  65. // overflow: hidden;
  66. // text-overflow: ellipsis;
  67. }
  68. </style>