From dfad7b14af57454bb6012c58a9479ba017b618f5 Mon Sep 17 00:00:00 2001 From: chenjiahan Date: Sat, 26 Sep 2020 10:56:16 +0800 Subject: [PATCH] chore(Picker): use relation --- src/picker/PickerColumn.js | 6 ++++-- src/picker/index.js | 10 ++++++---- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/picker/PickerColumn.js b/src/picker/PickerColumn.js index 26b203b0d..07dafe75a 100644 --- a/src/picker/PickerColumn.js +++ b/src/picker/PickerColumn.js @@ -9,7 +9,8 @@ import { preventDefault } from '../utils/dom/event'; // Composition import { useTouch } from '../composition/use-touch'; -import { useParent } from '../composition/use-parent'; +import { useExpose } from '../composition/use-expose'; +import { useParent } from '../composition/use-relation'; const DEFAULT_DURATION = 200; @@ -278,7 +279,8 @@ export default createComponent({ setIndex(state.index); - useParent(PICKER_KEY, { + useParent(PICKER_KEY); + useExpose({ state, setIndex, getValue, diff --git a/src/picker/index.js b/src/picker/index.js index 721e0ae32..ee342439e 100644 --- a/src/picker/index.js +++ b/src/picker/index.js @@ -1,4 +1,4 @@ -import { ref, watch, computed, provide, reactive } from 'vue'; +import { ref, watch, computed } from 'vue'; import { pickerProps, PICKER_KEY, DEFAULT_ITEM_HEIGHT } from './shared'; // Utils @@ -9,6 +9,7 @@ import { unitToPx } from '../utils/format/unit'; // Composition import { useExpose } from '../composition/use-expose'; +import { useChildren } from '../composition/use-relation'; // Components import Loading from '../loading'; @@ -40,9 +41,12 @@ export default createComponent({ emits: ['confirm', 'cancel', 'change'], setup(props, { emit, slots }) { - const children = reactive([]); const formattedColumns = ref([]); + const { children, linkChildren } = useChildren(PICKER_KEY); + + linkChildren(); + const itemHeight = computed(() => props.itemHeight ? unitToPx(props.itemHeight) : DEFAULT_ITEM_HEIGHT ); @@ -279,8 +283,6 @@ export default createComponent({ ); }; - provide(PICKER_KEY, { children }); - watch(() => props.columns, format, { immediate: true }); useExpose({