mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
19 lines
531 B
TypeScript
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');
|
|
});
|
|
}
|
|
}
|