From ce176e21900ee3fa7da22e75dec49779ea38193c Mon Sep 17 00:00:00 2001 From: 梁灏 Date: Tue, 13 Mar 2018 15:17:19 +0800 Subject: [PATCH] fixed #3081 --- examples/routers/input-number.vue | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------- src/components/input-number/input-number.vue | 18 +++++++++++++++++- 2 files changed, 71 insertions(+), 28 deletions(-) diff --git a/examples/routers/input-number.vue b/examples/routers/input-number.vue index db65699..e5bad09 100644 --- a/examples/routers/input-number.vue +++ b/examples/routers/input-number.vue @@ -1,39 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file + } + diff --git a/src/components/input-number/input-number.vue b/src/components/input-number/input-number.vue index b11f438..0acdcff 100644 --- a/src/components/input-number/input-number.vue +++ b/src/components/input-number/input-number.vue @@ -29,7 +29,7 @@ @change="change" :readonly="readonly || !editable" :name="name" - :value="precisionValue"> + :value="formatterValue"> @@ -113,6 +113,12 @@ }, elementId: { type: String + }, + formatter: { + type: Function + }, + parser: { + type: Function } }, data () { @@ -170,6 +176,13 @@ precisionValue () { // can not display 1.0 return this.precision ? this.currentValue.toFixed(this.precision) : this.currentValue; + }, + formatterValue () { + if (this.formatter) { + return this.formatter(this.precisionValue); + } else { + return this.precisionValue; + } } }, methods: { @@ -256,6 +269,9 @@ }, change (event) { let val = event.target.value.trim(); + if (this.parser) { + val = this.parser(val); + } if (event.type == 'input' && val.match(/^\-?\.?$|\.$/)) return; // prevent fire early if decimal. If no more input the change event will fire later -- libgit2 0.21.4