mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
types: improve Field injection typing (#8975)
* types: improve inject typing * types: update
This commit is contained in:
parent
11e856d099
commit
5c080f3a6e
@ -1,11 +1,11 @@
|
|||||||
import { ComponentInstance } from '../utils';
|
import { watch, inject, InjectionKey } from 'vue';
|
||||||
import { watch, inject } from 'vue';
|
import type { FieldProvide } from '../field/types';
|
||||||
|
|
||||||
export const FORM_KEY = Symbol('van-form');
|
export const FORM_KEY = Symbol('van-form');
|
||||||
export const FIELD_KEY = Symbol('van-field');
|
export const FIELD_KEY: InjectionKey<FieldProvide> = Symbol('van-field');
|
||||||
|
|
||||||
export function useLinkField(getValue: () => unknown) {
|
export function useLinkField(getValue: () => unknown) {
|
||||||
const field = inject(FIELD_KEY, null) as ComponentInstance | null;
|
const field = inject(FIELD_KEY, null);
|
||||||
|
|
||||||
if (field && !field.childFieldValue.value) {
|
if (field && !field.childFieldValue.value) {
|
||||||
field.childFieldValue.value = getValue;
|
field.childFieldValue.value = getValue;
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import type { Ref } from 'vue';
|
||||||
|
|
||||||
export type FieldType =
|
export type FieldType =
|
||||||
| 'tel'
|
| 'tel'
|
||||||
| 'text'
|
| 'text'
|
||||||
@ -37,6 +39,12 @@ export type FieldRule = {
|
|||||||
formatter?: (value: any, rule: FieldRule) => string;
|
formatter?: (value: any, rule: FieldRule) => string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type FieldProvide = {
|
||||||
|
childFieldValue: Ref<(() => unknown) | undefined>;
|
||||||
|
resetValidation: () => void;
|
||||||
|
validateWithTrigger: (trigger: FieldValidateTrigger) => void;
|
||||||
|
};
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface EventTarget {
|
interface EventTarget {
|
||||||
composing?: boolean;
|
composing?: boolean;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user