refactor(Field): refactor with composition-api
This commit is contained in:
@@ -1,17 +1,15 @@
|
||||
import { watch, inject, WatchSource, getCurrentInstance } from 'vue';
|
||||
import { watch, inject } from 'vue';
|
||||
import { FIELD_KEY } from '../field';
|
||||
|
||||
export function useParentField(watchSource: WatchSource) {
|
||||
export function useParentField(getValue: () => unknown) {
|
||||
const field = inject(FIELD_KEY, null) as any;
|
||||
|
||||
if (field && !field.children) {
|
||||
field.children = getCurrentInstance()!.proxy;
|
||||
if (field && !field.childFieldValue.value) {
|
||||
field.childFieldValue.value = getValue;
|
||||
|
||||
watch(watchSource, () => {
|
||||
if (field) {
|
||||
field.resetValidation();
|
||||
field.validateWithTrigger('onChange');
|
||||
}
|
||||
watch(getValue, () => {
|
||||
field.resetValidation();
|
||||
field.validateWithTrigger('onChange');
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user