From 19434520a0c39f2b6b20a5a9f0cd9772231acef1 Mon Sep 17 00:00:00 2001 From: DCloud_LXH <283700113@qq.com> Date: Mon, 21 Jun 2021 16:14:01 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=20=20input=E8=AE=BE?= =?UTF-8?q?=E7=BD=AEtype=3Dnumber=E5=92=8Cmaxlength=E6=97=B6=EF=BC=8C?= =?UTF-8?q?=E5=85=89=E6=A0=87=E7=A7=BB=E8=87=B3=E4=B8=AD=E9=97=B4=E5=8F=AF?= =?UTF-8?q?=E8=BE=93=E5=85=A5=E4=B8=94=E5=80=BC=E4=B8=8D=E5=90=8C=E6=AD=A5?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/view/components/input/index.vue | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/core/view/components/input/index.vue b/src/core/view/components/input/index.vue index d8d924100..26b15ec29 100644 --- a/src/core/view/components/input/index.vue +++ b/src/core/view/components/input/index.vue @@ -188,10 +188,15 @@ export default { if (this.inputType === 'number') { const maxlength = parseInt(this.maxlength, 10) if (maxlength > 0 && $event.target.value.length > maxlength) { - $event.target.value = $event.target.value.slice(0, maxlength) - this.valueSync = $event.target.value - // 字符长度超出范围不触发 input 事件 - outOfMaxlength = true + // 输入前字符长度超出范围,则不触发input,且将值还原 + // 否则截取一定长度且触发input + if (this.cachedValue.length === maxlength) { + this.valueSync = this.cachedValue + outOfMaxlength = true + } else { + $event.target.value = $event.target.value.slice(0, maxlength) + this.valueSync = $event.target.value + } } } -- GitLab