UNPKG

@vuesax-alpha/nightly

Version:
21 lines (18 loc) 667 B
import { getCurrentInstance, inject, computed, onUnmounted } from 'vue'; const useGroupInject = (key) => { const instance = getCurrentInstance(); if (!instance) { throw new Error( "useInject hook must be called inside setup function or <script setup>" ); } const parent = inject(key, void 0); const index = computed(() => (parent == null ? void 0 : parent.children.indexOf(instance)) || 0); parent == null ? void 0 : parent.insert(instance); onUnmounted(() => { parent == null ? void 0 : parent.remove(instance); }); return parent ? { ...parent, index } : void 0; }; export { useGroupInject }; //# sourceMappingURL=index.mjs.map