mirror of
https://gitee.com/vant-contrib/vant.git
synced 2025-04-06 03:57:59 +08:00
feat(@vant/use): useParent always return index (#8120)
This commit is contained in:
parent
faab7c03f0
commit
4ba646f2b6
@ -1,4 +1,5 @@
|
|||||||
import {
|
import {
|
||||||
|
ref,
|
||||||
inject,
|
inject,
|
||||||
computed,
|
computed,
|
||||||
onUnmounted,
|
onUnmounted,
|
||||||
@ -18,25 +19,25 @@ export function useParent<T>(key: string | symbol) {
|
|||||||
const parent = inject<ParentProvide<T> | null>(key, null);
|
const parent = inject<ParentProvide<T> | null>(key, null);
|
||||||
|
|
||||||
if (parent) {
|
if (parent) {
|
||||||
const instance = getCurrentInstance();
|
const instance = getCurrentInstance()!;
|
||||||
|
const { link, unlink, internalChildren, ...rest } = parent;
|
||||||
|
|
||||||
if (instance) {
|
link(instance);
|
||||||
const { link, unlink, internalChildren, ...rest } = parent;
|
|
||||||
|
|
||||||
link(instance);
|
onUnmounted(() => {
|
||||||
|
unlink(instance);
|
||||||
|
});
|
||||||
|
|
||||||
onUnmounted(() => {
|
const index = computed(() => internalChildren.indexOf(instance));
|
||||||
unlink(instance);
|
|
||||||
});
|
|
||||||
|
|
||||||
const index = computed(() => internalChildren.indexOf(instance));
|
return {
|
||||||
|
parent: rest,
|
||||||
return {
|
index,
|
||||||
parent: rest,
|
};
|
||||||
index,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return {};
|
return {
|
||||||
|
parent: null,
|
||||||
|
index: ref(-1),
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user