nutui-taro-upgrade
Version:
@nutui/nutui-taro 对京东风格组件库的taro4 版本支持
22 lines (21 loc) • 522 B
JavaScript
import { inject, getCurrentInstance, onUnmounted, computed } from "vue";
const useParent = (key) => {
const parent = inject(key, null);
if (parent) {
const instance = getCurrentInstance();
const { link, unlink, internalChildren } = parent;
link(instance);
onUnmounted(() => {
unlink(instance);
});
const index = computed(() => internalChildren.indexOf(instance));
return { parent, index };
}
return {
parent,
index: computed(() => -1)
};
};
export {
useParent as u
};