Commit 7a05b6e5f9adb76493d6d9b99133f48f1045678d

Authored by 梁灏
1 parent 36a91579

fixed #1810

examples/routers/input-number.vue
... ... @@ -6,7 +6,8 @@
6 6 <!--<div @click="changeMax">change max</div>-->
7 7 <!--<Input-number disabled :max="10" :min="1" :step="1.2" v-model="v2"></Input-number>-->
8 8 <!--<Input-number :max="10" :min="1" v-model="obj.v"></Input-number>-->
9   - <InputNumber :max="10" :min="1" v-model="value1"></InputNumber>
  9 + {{ value1 }}
  10 + <InputNumber :precision="1" :max="10" :min="1" :step="0.1" v-model="value1"></InputNumber>
10 11 </div>
11 12 </template>
12 13 <script>
... ... @@ -21,7 +22,7 @@
21 22 obj: {
22 23  
23 24 },
24   - value1: 1
  25 + value1: 1.0
25 26 };
26 27 },
27 28 computed: {},
... ...
src/components/input-number/input-number.vue
... ... @@ -25,7 +25,7 @@
25 25 @keydown.stop="keyDown"
26 26 @change="change"
27 27 :name="name"
28   - :value="currentValue">
  28 + :value="precisionValue">
29 29 </div>
30 30 </div>
31 31 </template>
... ... @@ -98,6 +98,9 @@
98 98 },
99 99 name: {
100 100 type: String
  101 + },
  102 + precision: {
  103 + type: Number
101 104 }
102 105 },
103 106 data () {
... ... @@ -151,6 +154,10 @@
151 154 },
152 155 inputClasses () {
153 156 return `${prefixCls}-input`;
  157 + },
  158 + precisionValue () {
  159 + // can not display 1.0
  160 + return this.currentValue.toFixed(this.precision);
154 161 }
155 162 },
156 163 methods: {
... ... @@ -208,6 +215,7 @@
208 215 this.setValue(val);
209 216 },
210 217 setValue (val) {
  218 + val = Number(Number(val).toFixed(this.precision));
211 219 this.$nextTick(() => {
212 220 this.currentValue = val;
213 221 this.$emit('input', val);
... ...