From 83295e655da9ae2debbf2e7472753517d5b5241d Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Wed, 16 Feb 2022 12:00:32 +0800 Subject: [PATCH] feat(Picker): add getSelectedOptions method --- packages/vant/src/picker/Picker.tsx | 4 +++- packages/vant/src/picker/README.md | 7 ++++--- packages/vant/src/picker/README.zh-CN.md | 7 ++++--- packages/vant/src/picker/types.ts | 1 + 4 files changed, 12 insertions(+), 7 deletions(-) diff --git a/packages/vant/src/picker/Picker.tsx b/packages/vant/src/picker/Picker.tsx index 86259a0f3..a57c35df2 100644 --- a/packages/vant/src/picker/Picker.tsx +++ b/packages/vant/src/picker/Picker.tsx @@ -285,7 +285,9 @@ export default defineComponent({ { immediate: true } ); - useExpose({ confirm }); + const getSelectedOptions = () => selectedOptions.value; + + useExpose({ confirm, getSelectedOptions }); return () => (
diff --git a/packages/vant/src/picker/README.md b/packages/vant/src/picker/README.md index cc5e9f3b1..f933f0a4b 100644 --- a/packages/vant/src/picker/README.md +++ b/packages/vant/src/picker/README.md @@ -355,9 +355,10 @@ export default { Use [ref](https://v3.vuejs.org/guide/component-template-refs.html) to get Picker instance and call instance methods. -| Name | Description | Attribute | Return value | -| ------- | ------------------------------------- | --------- | ------------ | -| confirm | Stop scrolling and emit confirm event | - | - | +| Name | Description | Attribute | Return value | +| --- | --- | --- | --- | +| confirm | Stop scrolling and emit confirm event | - | - | +| getSelectedOptions | Get current selected options | - | _PickerOption[]_ | ### Types diff --git a/packages/vant/src/picker/README.zh-CN.md b/packages/vant/src/picker/README.zh-CN.md index ea30293b4..4f577f1c4 100644 --- a/packages/vant/src/picker/README.zh-CN.md +++ b/packages/vant/src/picker/README.zh-CN.md @@ -374,9 +374,10 @@ export default { 通过 ref 可以获取到 Picker 实例并调用实例方法,详见[组件实例方法](#/zh-CN/advanced-usage#zu-jian-shi-li-fang-fa)。 -| 方法名 | 说明 | 参数 | 返回值 | -| ------- | --------------------------------- | ---- | ------ | -| confirm | 停止惯性滚动并触发 `confirm` 事件 | - | - | +| 方法名 | 说明 | 参数 | 返回值 | +| --- | --- | --- | --- | +| confirm | 停止惯性滚动并触发 `confirm` 事件 | - | - | +| getSelectedOptions | 获取当前选中的选项 | - | _PickerOption[]_ | ### 类型定义 diff --git a/packages/vant/src/picker/types.ts b/packages/vant/src/picker/types.ts index 635126330..b72e4105b 100644 --- a/packages/vant/src/picker/types.ts +++ b/packages/vant/src/picker/types.ts @@ -24,6 +24,7 @@ export type PickerColumn = PickerOption[]; export type PickerExpose = { confirm: () => void; + getSelectedOptions: () => PickerOption[]; }; export type PickerColumnProvide = {