Skip to content

Commit

Permalink
fix(input): 修复 input 内 preValue 计算错误问题(#3347)
Browse files Browse the repository at this point in the history
  • Loading branch information
SaberA1ter committed Jan 18, 2025
1 parent 39b69d5 commit b44c3ba
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/web-vue/components/input/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,14 +201,17 @@ export default defineComponent({
// 值相关
const _value = ref(props.defaultValue);
const computedValue = computed(() => props.modelValue ?? _value.value);
let preValue = computedValue.value;

watch(modelValue, (value) => {
if (isUndefined(value) || isNull(value)) {
_value.value = '';
}
});

let preValue = computedValue.value;
watch(computedValue, (value, oldValue) => {
preValue = oldValue;
});

// 状态相关
const focused = ref(false);
Expand Down Expand Up @@ -283,15 +286,13 @@ export default defineComponent({

const emitChange = (value: string, ev: Event) => {
if (value !== preValue) {
preValue = value;
emit('change', value, ev);
eventHandlers.value?.onChange?.(ev);
}
};

const handleFocus = (ev: FocusEvent) => {
focused.value = true;
preValue = computedValue.value;
emit('focus', ev);
eventHandlers.value?.onFocus?.(ev);
};
Expand Down

0 comments on commit b44c3ba

Please sign in to comment.