From 32eadbb5cb882ed2d34957430672a1d8f3eaa647 Mon Sep 17 00:00:00 2001 From: qiang Date: Wed, 2 Mar 2022 17:38:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(h5):=20=E4=BF=AE=E5=A4=8D=E9=83=A8=E5=88=86?= =?UTF-8?q?=E6=83=85=E5=86=B5=E4=B8=8Binput=E6=98=BE=E7=A4=BA=E6=95=B0?= =?UTF-8?q?=E5=80=BC=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98=EF=BC=88?= =?UTF-8?q?question/140366=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/view/components/input/index.vue | 5 +++++ src/core/view/mixins/field.js | 9 ++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/core/view/components/input/index.vue b/src/core/view/components/input/index.vue index bb97d65d5..7279062a8 100644 --- a/src/core/view/components/input/index.vue +++ b/src/core/view/components/input/index.vue @@ -148,6 +148,11 @@ export default { maxlength (value) { const realValue = this.valueSync.slice(0, parseInt(value, 10)) realValue !== this.valueSync && (this.valueSync = realValue) + }, + valueSync (value) { + if (this.type === 'number' && !(this.cachedValue === '-' && value === '')) { + this.cachedValue = value + } } }, created () { diff --git a/src/core/view/mixins/field.js b/src/core/view/mixins/field.js index 3821269f1..b3e1273ed 100644 --- a/src/core/view/mixins/field.js +++ b/src/core/view/mixins/field.js @@ -71,7 +71,7 @@ export default { data () { return { composing: false, - valueSync: this._getValueString(this.value), + valueSync: this._getValueString(this.value, this.type), focusSync: this.focus, // Safari 14 以上修正禁用状态颜色 fixColor: String(navigator.vendor).indexOf('Apple') === 0 && CSS.supports('image-orientation:from-image') @@ -117,7 +117,7 @@ export default { }, created () { const valueChange = this.__valueChange = debounce((val) => { - this.valueSync = this._getValueString(val) + this.valueSync = this._getValueString(val, this.type) }, 100) this.$watch('value', valueChange) this.__triggerInput = throttle(($event, detail) => { @@ -145,7 +145,10 @@ export default { } }, methods: { - _getValueString (value) { + _getValueString (value, type) { + if (type === 'number' && isNaN(Number(value))) { + value = '' + } return value === null ? '' : String(value) }, _initField (el) { -- GitLab