feat: add useParentField

This commit is contained in:
chenjiahan
2020-08-27 10:11:12 +08:00
parent 216417eae6
commit 0b147c5872
4 changed files with 26 additions and 6 deletions
+17
View File
@@ -0,0 +1,17 @@
import { watch, inject, WatchSource, getCurrentInstance } from 'vue';
import { FIELD_KEY } from '../field';
export function useParentField(watchSource: WatchSource) {
const field = inject(FIELD_KEY) as any;
if (field && !field.children) {
field.children = getCurrentInstance()!.proxy;
watch(watchSource, () => {
if (field) {
field.resetValidation();
field.validateWithTrigger('onChange');
}
});
}
}