chore(Picker): use relation

This commit is contained in:
chenjiahan 2020-09-26 10:56:16 +08:00
parent e4b7952061
commit dfad7b14af
2 changed files with 10 additions and 6 deletions

View File

@ -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,

View File

@ -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({