diff --git a/src/composition/use-parent.ts b/src/composition/use-parent.ts deleted file mode 100644 index 99ff4d8d0..000000000 --- a/src/composition/use-parent.ts +++ /dev/null @@ -1,30 +0,0 @@ -import { inject, computed, onUnmounted } from 'vue'; - -type Parent = { children: unknown[] }; - -type Child = T extends { children: (infer U)[] } ? U : never; - -export function useParent

( - key: string, - child = {} as Child

-) { - const parent = inject

(key, null); - - if (parent) { - const { children } = parent; - const index = computed(() => children.indexOf(child)); - - children.push(child); - - onUnmounted(() => { - children.splice(index.value, 1); - }); - - return { - index, - parent, - }; - } - - return {}; -} diff --git a/src/tabbar-item/index.js b/src/tabbar-item/index.js index 01ef863a0..9a88a9b49 100644 --- a/src/tabbar-item/index.js +++ b/src/tabbar-item/index.js @@ -5,7 +5,7 @@ import { TABBAR_KEY } from '../tabbar'; import { createNamespace, isObject, isDef } from '../utils'; // Composition -import { useParent } from '../composition/use-parent'; +import { useParent } from '../composition/use-relation'; import { routeProps, useRoute } from '../composition/use-route'; // Components diff --git a/src/tabbar/index.js b/src/tabbar/index.js index 4c174acb8..e18bdcafc 100644 --- a/src/tabbar/index.js +++ b/src/tabbar/index.js @@ -1,7 +1,12 @@ -import { ref, reactive, provide } from 'vue'; +import { ref } from 'vue'; + +// Utils import { createNamespace, isDef } from '../utils'; import { BORDER_TOP_BOTTOM } from '../utils/constant'; import { callInterceptor } from '../utils/interceptor'; + +// Composition +import { useChildren } from '../composition/use-relation'; import { usePlaceholder } from '../composition/use-placeholder'; const [createComponent, bem] = createNamespace('tabbar'); @@ -38,7 +43,7 @@ export default createComponent({ setup(props, { emit, slots }) { const root = ref(); - const children = reactive([]); + const { linkChildren } = useChildren(TABBAR_KEY); const renderPlaceholder = usePlaceholder(root, bem); const isUnfit = () => { @@ -76,11 +81,7 @@ export default createComponent({ } }; - provide(TABBAR_KEY, { - props, - children, - setActive, - }); + linkChildren({ props, setActive }); return () => { if (props.fixed && props.placeholder) {