Skip to content

Commit

Permalink
fix(input): 移除非必要的 modelValue 更新
Browse files Browse the repository at this point in the history
  • Loading branch information
eiinu committed May 16, 2024
1 parent 87f044d commit 649fa88
Showing 1 changed file with 6 additions and 13 deletions.
19 changes: 6 additions & 13 deletions src/packages/__VUE/input/input.taro.vue
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ const _onInput = (event: Event) => {
}
const updateValue = (value: string, trigger: InputFormatTrigger = 'onChange') => {
// #2178 & Taro #2642
emit('update:modelValue', value)
if (props.maxLength && value.length > Number(props.maxLength)) {
value = value.slice(0, Number(props.maxLength))
}
Expand All @@ -191,11 +189,15 @@ const updateValue = (value: string, trigger: InputFormatTrigger = 'onChange') =>
value = formatNumber(value, isDigit, isDigit)
}
if (props.formatter && trigger === props.formatTrigger) {
value = props.formatter(value)
const tempValue = props.formatter(value)
if (tempValue !== value) {
// #2178 & Taro #2642
emit('update:modelValue', value)
}
value = tempValue
}
if (value !== props.modelValue) {
emit('update:modelValue', value)
// emit('change', value);
}
}
Expand All @@ -205,7 +207,6 @@ const onFocus = (event: Event) => {
}
active.value = true
emit('focus', event)
// emit('update:modelValue', value);
}
const onBlur = (event: Event) => {
Expand All @@ -215,22 +216,14 @@ const onBlur = (event: Event) => {
setTimeout(() => {
active.value = false
}, 200)
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')
emit('blur', event)
// emit('update:modelValue', value);
}
const clear = (event: Event) => {
event.stopPropagation()
if (disabled.value) return
emit('update:modelValue', '', event)
// emit('change', '', event);
emit('clear', '', event)
}
Expand Down

0 comments on commit 649fa88

Please sign in to comment.