z-number.vue 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <template>
  2. <view class="flex-n fac">
  3. <view class="num-content flex-n fac" v-if="nowvalue>0">
  4. <view @click.stop="todo(0)" class="btn">-</view>
  5. <!-- <view class="text plr-20">{{nowvalue}}</view> -->
  6. <z-input class="z-number-input mlr-10" align="center" v-model="nowvalue" type="number"></z-input>
  7. </view>
  8. <view class="num-content" v-else></view>
  9. <view @click.stop="todo(1)" class="btn">+</view>
  10. </view>
  11. </template>
  12. <script>
  13. export default{
  14. props:{
  15. value:Number|String,
  16. },
  17. model:{
  18. prop:'value',
  19. event:'input'
  20. },
  21. data(){
  22. return{
  23. nowvalue:0
  24. }
  25. },
  26. watch:{
  27. value(newval,oldval){
  28. this.nowvalue=newval;
  29. this.$emit('input',this.nowvalue);
  30. },
  31. nowvalue(newval,oldval){
  32. this.$emit('input',this.nowvalue);
  33. this.$emit('change');
  34. }
  35. },
  36. mounted() {
  37. this.nowvalue=this.value
  38. },
  39. methods:{
  40. todo(state){
  41. if(state==0){
  42. if(this.nowvalue>0)
  43. this.nowvalue--;
  44. }else{
  45. this.nowvalue++;
  46. }
  47. this.$emit('input',this.nowvalue);
  48. this.$emit('change');
  49. }
  50. }
  51. }
  52. </script>
  53. <style lang="scss" scoped>
  54. .num-content{
  55. width: 120rpx;
  56. }
  57. .btn{
  58. color: #0075FF;
  59. font-size: 40rpx;
  60. }
  61. .text{
  62. font-size: 24rpx;
  63. color: #333333;
  64. white-space: nowrap;
  65. }
  66. .z-number-input{
  67. background: #f3f3f3;
  68. }
  69. </style>