From dbb4e1a48def8d895530669c729afe984c635aa0 Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Mon, 10 Oct 2022 11:57:00 +0800 Subject: [PATCH] fix: ios 16 input type=digit decimal point question/154584 --- src/core/view/components/input/index.vue | 27 ++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/core/view/components/input/index.vue b/src/core/view/components/input/index.vue index a8e5baaaa..e165d74bb 100644 --- a/src/core/view/components/input/index.vue +++ b/src/core/view/components/input/index.vue @@ -236,6 +236,33 @@ export default { $event.target.addEventListener('blur', clearCachedValue) return } + // 处理小数点 + if (this.cachedValue) { + if (this.cachedValue.indexOf('.') !== -1) { + // 删除到小数点时 + if ( + $event.data !== '.' && + $event.inputType === 'deleteContentBackward' + ) { + const dotIndex = this.cachedValue.indexOf('.') + this.cachedValue = + $event.target.value = + this.valueSync = + this.cachedValue.slice(0, dotIndex) + return this.$triggerInput($event, { + value: this.valueSync + }, force) + } + } else if ($event.data === '.') { + // 输入小数点时 + this.cachedValue += '.' + this.__clearCachedValue = () => { + this.cachedValue = $event.target.value = this.cachedValue.slice(0, -1) + } + $event.target.addEventListener('blur', this.__clearCachedValue) + return false + } + } this.cachedValue = this.valueSync = $event.target.value = this.cachedValue === '-' ? '' : this.cachedValue // 输入非法字符不触发 input 事件 return -- GitLab