Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(input): 修复 input 内 preValue 计算错误问题(#3347) #3427

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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