diff --git a/src/core/view/components/input/index.vue b/src/core/view/components/input/index.vue index bb97d65d53ceffeca2397512b9abad88cf3fb1b8..7279062a8bb27ac2e05c89c4c158275b735dee99 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 3821269f1b2710a7718c45356a0c444abdc239fd..b3e1273ed755a6abc17e6c722cc9b3ee6f0d2efc 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) {