@zebra-ui/swiper
Version:
专为多端设计的高性能swiper轮播组件库,支持多种复杂的 3D swiper轮播效果。
37 lines (30 loc) • 710 B
text/typescript
import {
ref,
inject,
computed,
onBeforeUnmount,
getCurrentInstance,
type ComponentInternalInstance
} from 'vue'
import type {
UseParent,
ParentProvide
} from '../../types/components/use-relation/use-parent'
export const useParent: UseParent = (key) => {
const parent = inject<ParentProvide | null>(key, null)
if (parent) {
const instance = getCurrentInstance() as ComponentInternalInstance
const { link, unlink, internalChildren } = parent
link(instance)
onBeforeUnmount(() => unlink(instance))
const index = computed(() => internalChildren.indexOf(instance))
return {
parent,
index
}
}
return {
parent: null,
index: ref(-1)
}
}