vant/src/composition/use-parent-field.ts
2020-09-21 16:48:40 +08:00

16 lines
393 B
TypeScript

import { watch, inject } from 'vue';
import { FIELD_KEY } from '../field';
export function useParentField(getValue: () => unknown) {
const field = inject(FIELD_KEY, null) as any;
if (field && !field.childFieldValue.value) {
field.childFieldValue.value = getValue;
watch(getValue, () => {
field.resetValidation();
field.validateWithTrigger('onChange');
});
}
}