diff --git a/packages/vant/src/area/Area.tsx b/packages/vant/src/area/Area.tsx index b059be877..629da5c72 100644 --- a/packages/vant/src/area/Area.tsx +++ b/packages/vant/src/area/Area.tsx @@ -188,15 +188,15 @@ export default defineComponent({ }; const setValues = () => { - let code = state.code || getDefaultCode(); const picker = pickerRef.value; - const province = getColumnValues('province'); - const city = getColumnValues('city', code.slice(0, 2)); if (!picker) { return; } + let code = state.code || getDefaultCode(); + const province = getColumnValues('province'); + const city = getColumnValues('city', code.slice(0, 2)); picker.setColumnValues(0, province); picker.setColumnValues(1, city); diff --git a/packages/vant/src/picker/PickerColumn.tsx b/packages/vant/src/picker/PickerColumn.tsx index 083dc4479..2768c8dd7 100644 --- a/packages/vant/src/picker/PickerColumn.tsx +++ b/packages/vant/src/picker/PickerColumn.tsx @@ -1,4 +1,4 @@ -import { ref, watch, reactive, defineComponent } from 'vue'; +import { ref, watch, reactive, defineComponent, type InjectionKey } from 'vue'; // Utils import { deepClone } from '../utils/deep-clone'; @@ -20,7 +20,7 @@ import { useTouch } from '../composables/use-touch'; import { useExpose } from '../composables/use-expose'; // Types -import type { PickerOption } from './types'; +import type { PickerOption, PickerColumnProvide } from './types'; const DEFAULT_DURATION = 200; @@ -38,7 +38,7 @@ function getElementTranslateY(element: Element) { return Number(translateY); } -export const PICKER_KEY = Symbol(name); +export const PICKER_KEY: InjectionKey = Symbol(name); const isOptionDisabled = (option: PickerOption) => isObject(option) && option.disabled; diff --git a/packages/vant/src/picker/types.ts b/packages/vant/src/picker/types.ts index 295c87895..342525dca 100644 --- a/packages/vant/src/picker/types.ts +++ b/packages/vant/src/picker/types.ts @@ -44,4 +44,18 @@ export type PickerExpose = { setColumnValues: (index: number, options: PickerOption[]) => void; }; +export type PickerColumnProvide = { + state: { + index: number; + offset: number; + duration: number; + options: PickerOption[]; + }; + setIndex: (index: number, emitChange?: boolean | undefined) => void; + getValue: () => PickerOption; + setValue: (value: string) => void; + setOptions: (options: PickerOption[]) => void; + stopMomentum: () => void; +}; + export type PickerInstance = ComponentPublicInstance;