diff --git a/packages/core/src/affix/index.ts b/packages/core/src/affix/index.ts index edaf793..ca27dd6 100644 --- a/packages/core/src/affix/index.ts +++ b/packages/core/src/affix/index.ts @@ -63,7 +63,7 @@ export const useAffix = defineHookComponent({ setup(props, { emit }) { const wrapperRef = ref(null); - const parentRef = inject(AFFIX_TARGET_KEY, undefined); + const parentRef = inject(AFFIX_TARGET_KEY, null); const targetRef = useElement(props.target, parentRef); @@ -164,3 +164,9 @@ export const useAffix = defineHookComponent({ export function provideAffixTarget(target: MaybeRefOrGetter) { provide(AFFIX_TARGET_KEY, target); } + +export function useAffixTargetProvider() { + const targetRef = ref(null); + provideAffixTarget(targetRef); + return targetRef; +}