refactor(Field): refactor with composition-api

This commit is contained in:
chenjiahan
2020-09-21 16:48:40 +08:00
parent 7e86fb9e43
commit 00dbf2cc50
4 changed files with 317 additions and 335 deletions
+7 -9
View File
@@ -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');
});
}
}