vant/src/composables/use-link-field.ts
neverland 5c080f3a6e
types: improve Field injection typing (#8975)
* types: improve inject typing

* types: update
2021-07-03 20:05:14 +08:00

19 lines
531 B
TypeScript

import { watch, inject, InjectionKey } from 'vue';
import type { FieldProvide } from '../field/types';
export const FORM_KEY = Symbol('van-form');
export const FIELD_KEY: InjectionKey<FieldProvide> = Symbol('van-field');
export function useLinkField(getValue: () => unknown) {
const field = inject(FIELD_KEY, null);
if (field && !field.childFieldValue.value) {
field.childFieldValue.value = getValue;
watch(getValue, () => {
field.resetValidation();
field.validateWithTrigger('onChange');
});
}
}