From 61ef6b9a985eaabe4133ae33d20d7c050ab9b1f8 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Sun, 28 Aug 2022 10:50:49 +0800 Subject: [PATCH] chore(Picker): add getEventParams function --- packages/vant/src/picker/Picker.tsx | 32 +++++++++++------------------ 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/packages/vant/src/picker/Picker.tsx b/packages/vant/src/picker/Picker.tsx index b4ba81d75..c94801959 100644 --- a/packages/vant/src/picker/Picker.tsx +++ b/packages/vant/src/picker/Picker.tsx @@ -126,6 +126,11 @@ export default defineComponent({ } }; + const getEventParams = () => ({ + selectedValues: selectedValues.value, + selectedOptions: selectedOptions.value, + }); + const onChange = (value: Numeric, columnIndex: number) => { setValue(columnIndex, value); @@ -142,34 +147,21 @@ export default defineComponent({ }); } - emit('change', { - columnIndex, - selectedValues: selectedValues.value, - selectedOptions: selectedOptions.value, - }); + emit('change', extend({ columnIndex }, getEventParams())); }; const onClickOption = (currentOption: PickerOption, columnIndex: number) => - emit('clickOption', { - columnIndex, - currentOption, - selectedValues: selectedValues.value, - selectedOptions: selectedOptions.value, - }); + emit( + 'clickOption', + extend({ columnIndex, currentOption }, getEventParams()) + ); const confirm = () => { children.forEach((child) => child.stopMomentum()); - emit('confirm', { - selectedValues: selectedValues.value, - selectedOptions: selectedOptions.value, - }); + emit('confirm', getEventParams()); }; - const cancel = () => - emit('cancel', { - selectedValues: selectedValues.value, - selectedOptions: selectedOptions.value, - }); + const cancel = () => emit('cancel', getEventParams()); const renderColumnItems = () => currentColumns.value.map((options, columnIndex) => (