diff --git a/packages/@core/ui-kit/form-ui/src/vben-use-form.vue b/packages/@core/ui-kit/form-ui/src/vben-use-form.vue index 27a8351c7b9..9908e85d315 100644 --- a/packages/@core/ui-kit/form-ui/src/vben-use-form.vue +++ b/packages/@core/ui-kit/form-ui/src/vben-use-form.vue @@ -6,7 +6,7 @@ import type { ExtendedFormApi, VbenFormProps } from './types'; import { useForwardPriorityValues } from '@vben-core/composables'; // import { isFunction } from '@vben-core/shared/utils'; -import { nextTick, onMounted, useTemplateRef, watch } from 'vue'; +import { nextTick, onMounted, watch } from 'vue'; import { cloneDeep } from '@vben-core/shared/utils'; @@ -27,8 +27,6 @@ interface Props extends VbenFormProps { const props = defineProps(); -const formActionsRef = useTemplateRef('formActionsRef'); - const state = props.formApi?.useStore?.(); const forward = useForwardPriorityValues(props, state); @@ -44,11 +42,7 @@ const handleUpdateCollapsed = (value: boolean) => { }; function handleKeyDownEnter(event: KeyboardEvent) { - if ( - !state.value.submitOnEnter || - !formActionsRef.value || - !formActionsRef.value.handleSubmit - ) { + if (!state.value.submitOnEnter || !forward.value.formApi?.isMounted) { return; } // 如果是 textarea 不阻止默认行为,否则会导致无法换行。 @@ -58,12 +52,12 @@ function handleKeyDownEnter(event: KeyboardEvent) { } event.preventDefault(); - formActionsRef.value?.handleSubmit?.(); + forward.value.formApi.validateAndSubmitForm(); } const handleValuesChangeDebounced = useDebounceFn((newVal) => { forward.value.handleValuesChange?.(cloneDeep(newVal)); - state.value.submitOnChange && formActionsRef.value?.handleSubmit?.(); + state.value.submitOnChange && forward.value.formApi?.validateAndSubmitForm(); }, 300); onMounted(async () => { @@ -94,7 +88,6 @@ onMounted(async () => {