From 91582e27ce19ac0ea2cd2266e0ac750d0a05e464 Mon Sep 17 00:00:00 2001 From: eiinu Date: Thu, 30 Mar 2023 10:10:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(input):=20format=E3=80=81clear=20=E5=8A=9F?= =?UTF-8?q?=E8=83=BD=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/packages/__VUE/input/index.taro.vue | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/src/packages/__VUE/input/index.taro.vue b/src/packages/__VUE/input/index.taro.vue index e8f8ab27f..fdd7c9843 100644 --- a/src/packages/__VUE/input/index.taro.vue +++ b/src/packages/__VUE/input/index.taro.vue @@ -272,7 +272,6 @@ export default create({ emits: [ 'update:modelValue', - 'change', 'blur', 'focus', 'clear', @@ -332,13 +331,14 @@ export default create({ const onInput = (event: Event) => { const input = event.target as HTMLInputElement; let value = input.value; - if (props.maxLength && value.length > Number(props.maxLength)) { - value = value.slice(0, Number(props.maxLength)); - } + emit('update:modelValue', value); updateValue(value); }; const updateValue = (value: string, trigger: InputFormatTrigger = 'onChange') => { + if (props.maxLength && value.length > Number(props.maxLength)) { + value = value.slice(0, Number(props.maxLength)); + } if (props.type === 'digit') { value = formatNumber(value, false, false); } @@ -350,13 +350,8 @@ export default create({ value = props.formatter(value); } - if (inputRef?.value.value !== value) { - inputRef.value.value = value; - } - if (value !== props.modelValue) { emit('update:modelValue', value); - emit('change', value); } }; @@ -381,10 +376,7 @@ export default create({ const input = event.target as HTMLInputElement; let value = input.value; - if (props.maxLength && value.length > Number(props.maxLength)) { - value = value.slice(0, Number(props.maxLength)); - } - updateValue(getModelValue(), 'onBlur'); + updateValue(value, 'onBlur'); emit('blur', event); emit('update:modelValue', value); }; @@ -392,6 +384,7 @@ export default create({ const clear = (event: Event) => { event.stopPropagation(); if (props.disabled) return; + emit('update:modelValue', '', event); emit('clear', '', event); }; -- GitLab