表单校验有问题修复,必填的form的validate校验反过来了 #issues/4189
							parent
							
								
									d9eaf06d7d
								
							
						
					
					
						commit
						79571477cf
					
				|  | @ -1,5 +1,6 @@ | ||||||
| import type { UnwrapRef, Ref, WritableComputedRef, DeepReadonly } from 'vue'; | import type { UnwrapRef, Ref, WritableComputedRef, DeepReadonly } from 'vue'; | ||||||
| import { reactive, readonly, computed, getCurrentInstance, watchEffect, unref, nextTick, toRaw } from 'vue'; | import { reactive, readonly, computed, getCurrentInstance, watchEffect, unref, nextTick, toRaw } from 'vue'; | ||||||
|  | import {Form} from "ant-design-vue"; | ||||||
| 
 | 
 | ||||||
| import { isEqual } from 'lodash-es'; | import { isEqual } from 'lodash-es'; | ||||||
| export function useRuleFormItem<T extends Recordable, K extends keyof T, V = UnwrapRef<T[K]>>( | 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[]>) { | export function useRuleFormItem<T extends Recordable>(props: T, key: keyof T = 'value', changeEvent = 'change', emitData?: Ref<any[]>) { | ||||||
|   const instance = getCurrentInstance(); |   const instance = getCurrentInstance(); | ||||||
|   const emit = instance?.emit; |   const emit = instance?.emit; | ||||||
|  |   const formItemContext = Form.useInjectFormItemContext(); | ||||||
| 
 | 
 | ||||||
|   const innerState = reactive({ |   const innerState = reactive({ | ||||||
|     value: props[key], |     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]; |       innerState.value = value as T[keyof T]; | ||||||
|       nextTick(() => { |       nextTick(() => { | ||||||
|         emit?.(changeEvent, value, ...(toRaw(unref(emitData)) || [])); |         emit?.(changeEvent, value, ...(toRaw(unref(emitData)) || [])); | ||||||
|  |         // https://antdv.com/docs/vue/migration-v3-cn
 | ||||||
|  |         // antDv3升级后需要调用这个方法更新校验的值
 | ||||||
|  |         nextTick(() => formItemContext.onFieldChange()); | ||||||
|       }); |       }); | ||||||
|     }, |     }, | ||||||
|   }); |   }); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 zhangdaiscott
						zhangdaiscott