fix: form submission not appropriate (#5126)
parent
cbca9ffd95
commit
1d3729aa24
|
@ -6,7 +6,9 @@ import type { ExtendedFormApi, VbenFormProps } from './types';
|
||||||
import { useForwardPriorityValues } from '@vben-core/composables';
|
import { useForwardPriorityValues } from '@vben-core/composables';
|
||||||
// import { isFunction } from '@vben-core/shared/utils';
|
// import { isFunction } from '@vben-core/shared/utils';
|
||||||
|
|
||||||
import { toRaw, useTemplateRef, watch } from 'vue';
|
import { nextTick, onMounted, useTemplateRef, watch } from 'vue';
|
||||||
|
|
||||||
|
import { cloneDeep } from '@vben-core/shared/utils';
|
||||||
|
|
||||||
import { useDebounceFn } from '@vueuse/core';
|
import { useDebounceFn } from '@vueuse/core';
|
||||||
|
|
||||||
|
@ -59,14 +61,16 @@ function handleKeyDownEnter(event: KeyboardEvent) {
|
||||||
formActionsRef.value?.handleSubmit?.();
|
formActionsRef.value?.handleSubmit?.();
|
||||||
}
|
}
|
||||||
|
|
||||||
watch(
|
const handleValuesChangeDebounced = useDebounceFn((newVal) => {
|
||||||
() => form.values,
|
forward.value.handleValuesChange?.(cloneDeep(newVal));
|
||||||
useDebounceFn(() => {
|
state.value.submitOnChange && formActionsRef.value?.handleSubmit?.();
|
||||||
forward.value.handleValuesChange?.(toRaw(form.values));
|
}, 300);
|
||||||
state.value.submitOnChange && props.formApi?.submitForm();
|
|
||||||
}, 300),
|
onMounted(async () => {
|
||||||
{ deep: true },
|
// 只在挂载后开始监听,form.values会有一个初始化的过程
|
||||||
);
|
await nextTick();
|
||||||
|
watch(() => form.values, handleValuesChangeDebounced, { deep: true });
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
|
|
Loading…
Reference in New Issue