This commit is contained in:
梁灏 2017-09-15 11:44:09 +08:00
parent 36a9157947
commit 7a05b6e5f9
2 changed files with 12 additions and 3 deletions

View file

@ -6,7 +6,8 @@
<!--<div @click="changeMax">change max</div>--> <!--<div @click="changeMax">change max</div>-->
<!--<Input-number disabled :max="10" :min="1" :step="1.2" v-model="v2"></Input-number>--> <!--<Input-number disabled :max="10" :min="1" :step="1.2" v-model="v2"></Input-number>-->
<!--<Input-number :max="10" :min="1" v-model="obj.v"></Input-number>--> <!--<Input-number :max="10" :min="1" v-model="obj.v"></Input-number>-->
<InputNumber :max="10" :min="1" v-model="value1"></InputNumber> {{ value1 }}
<InputNumber :precision="1" :max="10" :min="1" :step="0.1" v-model="value1"></InputNumber>
</div> </div>
</template> </template>
<script> <script>
@ -21,7 +22,7 @@
obj: { obj: {
}, },
value1: 1 value1: 1.0
}; };
}, },
computed: {}, computed: {},

View file

@ -25,7 +25,7 @@
@keydown.stop="keyDown" @keydown.stop="keyDown"
@change="change" @change="change"
:name="name" :name="name"
:value="currentValue"> :value="precisionValue">
</div> </div>
</div> </div>
</template> </template>
@ -98,6 +98,9 @@
}, },
name: { name: {
type: String type: String
},
precision: {
type: Number
} }
}, },
data () { data () {
@ -151,6 +154,10 @@
}, },
inputClasses () { inputClasses () {
return `${prefixCls}-input`; return `${prefixCls}-input`;
},
precisionValue () {
// can not display 1.0
return this.currentValue.toFixed(this.precision);
} }
}, },
methods: { methods: {
@ -208,6 +215,7 @@
this.setValue(val); this.setValue(val);
}, },
setValue (val) { setValue (val) {
val = Number(Number(val).toFixed(this.precision));
this.$nextTick(() => { this.$nextTick(() => {
this.currentValue = val; this.currentValue = val;
this.$emit('input', val); this.$emit('input', val);