index.vue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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: 6rpx;
  36. box-sizing: border-box;
  37. left: 74rpx;
  38. line-height: 35rpx;
  39. background: #FF2923;
  40. border: 4rpx solid white;
  41. border-top-left-radius: 20rpx;
  42. border-top-right-radius: 20rpx;
  43. border-bottom-right-radius: 20rpx;
  44. border-bottom-left-radius: 20rpx;
  45. }
  46. .m-badge {
  47. font-family: 'PingFang SC';
  48. font-style: normal;
  49. font-size: 24rpx;
  50. min-width: 4rpx;
  51. height: 30rpx;
  52. font-weight: 500;
  53. padding: 0 8rpx;
  54. text-align: center;
  55. display: flex;
  56. flex-direction: row;
  57. justify-content: center;
  58. align-items: center;
  59. text-align: center;
  60. color: white;
  61. // text-overflow: -o-ellipsis-lastline;
  62. // overflow: hidden; //溢出内容隐藏
  63. // text-overflow: ellipsis; //文本溢出部分用省略号表示
  64. // display: -webkit-box; //特别显示模式
  65. // -webkit-line-clamp: 1; //行数
  66. // line-clamp: 1;
  67. // -webkit-box-orient: vertical; //盒子中内容竖直排列
  68. white-space: nowrap;
  69. // overflow: hidden;
  70. // text-overflow: ellipsis;
  71. }
  72. </style>