Browse Source

fix: 步进器精度丢失

zhangyufei 5 years ago
parent
commit
c2bbbf418f
1 changed files with 7 additions and 8 deletions
  1. 7 8
      src/packages/stepper/demo.vue

+ 7 - 8
src/packages/stepper/demo.vue

@@ -4,7 +4,7 @@
     <div>
     <div>
       <nut-cell>
       <nut-cell>
         <span slot="title">
         <span slot="title">
-          <nut-stepper @focus="focus" :blur="blur" :value.sync="val1" :max="12" :step="0.1" :decimalPlaces="1" @add="add"></nut-stepper>
+          <nut-stepper @focus="focus" :blur="blur" :value.sync="val1" :max="12" :step="0.1" :decimalPlaces="1"></nut-stepper>
         </span>
         </span>
         <span slot="desc">
         <span slot="desc">
           value: {{ val1 }} <button @click="reduce" class="demo-btn">-</button> <button @click="add" class="demo-btn">+</button>
           value: {{ val1 }} <button @click="reduce" class="demo-btn">-</button> <button @click="add" class="demo-btn">+</button>
@@ -63,7 +63,7 @@ export default {
       val3: 5,
       val3: 5,
       val4: 0,
       val4: 0,
       val5: 0,
       val5: 0,
-      val6: 0
+      val6: 0,
     };
     };
   },
   },
   methods: {
   methods: {
@@ -79,14 +79,13 @@ export default {
     blur(e, v) {
     blur(e, v) {
       console.log('blur,', e, v);
       console.log('blur,', e, v);
     },
     },
-    add(v) {
-      console.log(v);
-      // this.val1 = Number(this.val1) + 1;
+    add() {
+      this.val1 = (Number(this.val1) + Number(0.1)).toFixed(1);
     },
     },
     reduce() {
     reduce() {
-      this.val1 = Math.max(Number(this.val1) - 1, 0);
-    }
-  }
+      this.val1 = Math.max(Number(this.val1) - 1, 0).toFixed(1);
+    },
+  },
 };
 };
 </script>
 </script>