Commit 4d093b5070f36444538a1799a6369446e1c429a6

Authored by huanghong
1 parent 354254b4

fixed input-number null bug

examples/routers/input-number.vue
... ... @@ -41,7 +41,7 @@
41 41  
42 42 <template>
43 43 <div>
44   - <InputNumber :max="1000000000" :min="1" v-model="value1" :formatter="formatter" :parser="parser" @on-change="change" style="width: 200px"></InputNumber>
  44 + <!-- <InputNumber :max="1000000000" :min="1" v-model="value1" :formatter="formatter" :parser="parser" @on-change="change" style="width: 200px"></InputNumber>
45 45 <InputNumber :max="1000000000" :min="1" v-model="value2" :formatter="formatter2" :parser="parser2" @on-change="change" style="width: 200px"></InputNumber>
46 46  
47 47 <InputNumber @on-change="change" style="width: 200px"></InputNumber>
... ... @@ -51,7 +51,10 @@
51 51  
52 52 <InputNumber v-model="value2" @on-focus="focus" style="width: 200px"></InputNumber>
53 53  
54   - <InputNumber v-model="value3" style="width: 200px" placeholder="Enter something..."></InputNumber>
  54 + <InputNumber v-model="value3" style="width: 200px" placeholder="Enter something..."></InputNumber> -->
  55 +
  56 +
  57 + <InputNumber v-model="valueNull" style="width: 200px" :min='0' :max='10000' :precision='2' ></InputNumber>
55 58 </div>
56 59 </template>
57 60 <script>
... ...
src/components/input-number/input-number.vue
... ... @@ -181,6 +181,7 @@
181 181 },
182 182 precisionValue () {
183 183 // can not display 1.0
  184 + if(!this.currentValue) return this.currentValue;
184 185 return this.precision ? this.currentValue.toFixed(this.precision) : this.currentValue;
185 186 },
186 187 formatterValue () {
... ... @@ -247,7 +248,10 @@
247 248 },
248 249 setValue (val) {
249 250 // 如果 step 是小数,且没有设置 precision,是有问题的
250   - if (!isNaN(this.precision)) val = Number(Number(val).toFixed(this.precision));
  251 + if(val){
  252 + if (!isNaN(this.precision)) val = Number(Number(val).toFixed(this.precision));
  253 + }
  254 +
251 255  
252 256 this.$nextTick(() => {
253 257 this.currentValue = val;
... ...