表单校验有问题修复,必填的form的validate校验反过来了 #issues/4189

pull/237/head
zhangdaiscott 2022-11-08 22:00:25 +08:00
parent d9eaf06d7d
commit 79571477cf
1 changed files with 5 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import type { UnwrapRef, Ref, WritableComputedRef, DeepReadonly } from 'vue';
import { reactive, readonly, computed, getCurrentInstance, watchEffect, unref, nextTick, toRaw } from 'vue';
import {Form} from "ant-design-vue";
import { isEqual } from 'lodash-es';
export function useRuleFormItem<T extends Recordable, K extends keyof T, V = UnwrapRef<T[K]>>(
@ -11,6 +12,7 @@ export function useRuleFormItem<T extends Recordable, K extends keyof T, V = Unw
export function useRuleFormItem<T extends Recordable>(props: T, key: keyof T = 'value', changeEvent = 'change', emitData?: Ref<any[]>) {
const instance = getCurrentInstance();
const emit = instance?.emit;
const formItemContext = Form.useInjectFormItemContext();
const innerState = reactive({
value: props[key],
@ -37,6 +39,9 @@ export function useRuleFormItem<T extends Recordable>(props: T, key: keyof T = '
innerState.value = value as T[keyof T];
nextTick(() => {
emit?.(changeEvent, value, ...(toRaw(unref(emitData)) || []));
// https://antdv.com/docs/vue/migration-v3-cn
// antDv3升级后需要调用这个方法更新校验的值
nextTick(() => formItemContext.onFieldChange());
});
},
});