count2.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <template>
  2. <view class="countContainer">
  3. <view class="reduceBtn" @click="toReduce" />
  4. <input
  5. v-model="countNum"
  6. class="countNum"
  7. :class="Number(countNum) > 0 ? 'active' : ''"
  8. />
  9. <view class="plusBtn" @click="toPlus" />
  10. </view>
  11. </template>
  12. <script>
  13. export default {
  14. props: {
  15. countNum: {
  16. type: Number,
  17. default: 0
  18. }
  19. },
  20. methods: {
  21. toReduce() {
  22. let _v = this.countNum
  23. if(_v === 0) return false
  24. this.$emit('update:countNum', --_v)
  25. },
  26. toPlus() {
  27. let _v = this.countNum
  28. if(_v > 999) return false
  29. this.$emit('update:countNum', ++_v)
  30. }
  31. }
  32. }
  33. </script>
  34. <style lang="scss" scoped>
  35. .countContainer {
  36. flex: 1;
  37. overflow: hidden;
  38. height: 64rpx;
  39. border: 1px solid #F76454;
  40. box-sizing: border-box;
  41. border-radius: 16rpx;
  42. display: flex;
  43. align-items: center;
  44. justify-content: space-between;
  45. background-color: #FFF4F3;
  46. .reduceBtn, .plusBtn {
  47. width: 60rpx;
  48. height: 100%;
  49. display: flex;
  50. align-items: center;
  51. justify-content: center;
  52. position: relative;
  53. &::before {
  54. content: "";
  55. display: block;
  56. width: 18rpx;
  57. height: 2rpx;
  58. background-color: #F76454;
  59. }
  60. &.plusBtn {
  61. &::after {
  62. content: "";
  63. display: block;
  64. position: absolute;
  65. width: 2rpx;
  66. height: 18rpx;
  67. background-color: #F76454;
  68. top: 50%;
  69. left: 50%;
  70. transform: translate(-50%, -50%);
  71. }
  72. }
  73. }
  74. .countNum {
  75. flex: 1;
  76. overflow: hidden;
  77. border-left: 1px solid #F76454;
  78. border-right: 1px solid #F76454;
  79. text-align: center;
  80. line-height: 72rpx;
  81. height: 100%;
  82. &.active {
  83. color: #F76454;
  84. }
  85. }
  86. }
  87. </style>