custom-counter.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <template>
  2. <view class="custom-counter">
  3. <text class="reduce cuIcon-move" @tap="reduce"></text>
  4. <text class="num">{{ inputValue }}</text>
  5. <text class="add cuIcon-add" @tap="add"></text>
  6. </view>
  7. </template>
  8. <script>
  9. export default {
  10. props: {
  11. value: String
  12. },
  13. data() {
  14. return {
  15. inputValue: this.value
  16. }
  17. },
  18. methods: {
  19. add () {
  20. if (this.inputValue < 99) {
  21. this.inputValue ++
  22. this.$emit('input', this.inputValue)
  23. }
  24. },
  25. reduce () {
  26. if (+this.inputValue) {
  27. this.inputValue --
  28. this.$emit('input', this.inputValue)
  29. }
  30. }
  31. }
  32. }
  33. </script>
  34. <style lang="scss" scoped>
  35. .custom-counter {
  36. display: flex;
  37. justify-content: space-between;
  38. align-items: center;
  39. width: 212rpx;
  40. height: 50rpx;
  41. border-radius:5rpx;
  42. font-size: 32rpx;
  43. color: rgba(42, 42, 42, 1);
  44. text {
  45. display: flex;
  46. justify-content: center;
  47. align-items: center;
  48. width: 90rpx;
  49. height: 100%;
  50. background: #EEEEEE;
  51. border-radius: 6rpx;
  52. &.num {
  53. background: #FFFFFF;
  54. border-radius: 0;
  55. }
  56. }
  57. .reduce, .add {
  58. width: 50rpx;
  59. height: 50rpx;
  60. border-radius: 50%;
  61. box-sizing: border-box;
  62. }
  63. .add {
  64. background-color: #FA6342;
  65. color: #FFFFFF;
  66. }
  67. .reduce {
  68. border: 2rpx solid #B5B5B5;
  69. color: #B5B5B5;
  70. background-color: #FFFFFF;
  71. }
  72. }
  73. </style>