feat(@vant/use): useParent always return index (#8120)

This commit is contained in:
neverland 2021-02-10 11:03:36 +08:00 committed by GitHub
parent faab7c03f0
commit 4ba646f2b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,4 +1,5 @@
import { import {
ref,
inject, inject,
computed, computed,
onUnmounted, onUnmounted,
@ -18,9 +19,7 @@ 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()!;
if (instance) {
const { link, unlink, internalChildren, ...rest } = parent; const { link, unlink, internalChildren, ...rest } = parent;
link(instance); link(instance);
@ -36,7 +35,9 @@ export function useParent<T>(key: string | symbol) {
index, index,
}; };
} }
}
return {}; return {
parent: null,
index: ref(-1),
};
} }