File tree Expand file tree Collapse file tree 4 files changed +27
-2
lines changed Expand file tree Collapse file tree 4 files changed +27
-2
lines changed Original file line number Diff line number Diff line change 2
2
import { menuProps } from ' ./props'
3
3
import { ACard } from ' @/components'
4
4
import { AFloating } from ' @/components/floating'
5
+ import { useParent } from ' @/composables'
5
6
6
7
const props = defineProps (menuProps )
7
8
@@ -18,7 +19,7 @@ defineOptions({
18
19
name: ' AMenu' ,
19
20
})
20
21
21
- const parentEl = useParentElement ()
22
+ const parentEl = useParent ()
22
23
</script >
23
24
24
25
<template >
Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ import type { Middleware } from '@floating-ui/vue'
5
5
import { flip , offset , shift } from ' @floating-ui/vue'
6
6
import { tooltipProps } from ' ./props'
7
7
import { AFloating } from ' @/components/floating'
8
+ import { useParent } from ' @/composables'
8
9
9
10
const props = defineProps (tooltipProps )
10
11
@@ -20,7 +21,10 @@ defineOptions({
20
21
name: ' ATooltip' ,
21
22
})
22
23
23
- const parentEl = useParentElement ()
24
+ const parentEl = useParent ()
25
+ onMounted (() => {
26
+ console .log (' parentEl :>> ' , parentEl .value )
27
+ })
24
28
25
29
// const arrowEl = ref()
26
30
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ export * from './useDOMScrollLock'
6
6
export * from './useGroupModel'
7
7
export * from './useIndeterminateCheckbox'
8
8
export * from './useLayer'
9
+ export * from './useParent'
9
10
export * from './useSearch'
10
11
export * from './useSort'
11
12
export * from './useTeleport'
Original file line number Diff line number Diff line change
1
+ import type { Ref } from 'vue'
2
+
3
+ export function useParent ( ) : Readonly < Ref < HTMLElement | SVGElement | null | undefined > > {
4
+ const parentElement = shallowRef < HTMLElement | SVGElement | null | undefined > ( )
5
+
6
+ const update = ( ) => {
7
+ const vm = getCurrentInstance ( )
8
+
9
+ const parentEl = vm ! . parent ! . vnode . el
10
+ const proxyParentEl = vm ! . proxy ! . $el . parentElement
11
+
12
+ // @ts -expect-error - `vm!.vnode.ctx` give type error
13
+ parentElement . value = vm ! . vnode . ctx === vm ! . vnode . el ! . parentElement . __vnode . ctx ? proxyParentEl : parentEl
14
+ }
15
+
16
+ tryOnMounted ( update )
17
+
18
+ return parentElement
19
+ }
You can’t perform that action at this time.
0 commit comments