File tree 3 files changed +35
-6
lines changed
packages/runtime-vapor/src
3 files changed +35
-6
lines changed Original file line number Diff line number Diff line change
1
+ import {
2
+ type SetupContext ,
3
+ createSetupContext ,
4
+ getCurrentInstance ,
5
+ } from './component'
6
+ import { warn } from './warning'
7
+
8
+ // TODO: warning compiler-macros runtime usages
9
+
10
+ export function useSlots ( ) : SetupContext [ 'slots' ] {
11
+ return getContext ( ) . slots
12
+ }
13
+
14
+ export function useAttrs ( ) : SetupContext [ 'attrs' ] {
15
+ return getContext ( ) . attrs
16
+ }
17
+
18
+ function getContext ( ) : SetupContext {
19
+ const i = getCurrentInstance ( ) !
20
+ if ( __DEV__ && ! i ) {
21
+ warn ( `useContext() called without active instance.` )
22
+ }
23
+ return i . setupContext || ( i . setupContext = createSetupContext ( i ) )
24
+ }
Original file line number Diff line number Diff line change @@ -110,6 +110,7 @@ export {
110
110
onErrorCaptured ,
111
111
// onServerPrefetch,
112
112
} from './apiLifecycle'
113
+ export { useAttrs , useSlots } from './apiSetupHelpers'
113
114
export {
114
115
createVaporApp ,
115
116
type App ,
Original file line number Diff line number Diff line change 1
1
<script setup lang="ts">
2
2
import {
3
- getCurrentInstance ,
4
3
onBeforeMount ,
5
4
onBeforeUnmount ,
6
5
onMounted ,
7
6
onUnmounted ,
7
+ useAttrs ,
8
8
watchEffect ,
9
9
} from ' vue/vapor'
10
10
@@ -14,7 +14,7 @@ const props = defineProps<{
14
14
baz: string
15
15
}>()
16
16
17
- const attrs = getCurrentInstance ()?. attrs
17
+ const attrs = useAttrs ()
18
18
19
19
watchEffect (() => {
20
20
console .log ({ ... attrs })
@@ -29,8 +29,12 @@ onUnmounted(() => console.log('sub: unmounted'))
29
29
</script >
30
30
31
31
<template >
32
- <div >sub-comp</div >
33
- {{ props }}
34
- {{ attrs }}
35
- {{ keys(attrs) }}
32
+ <h2 >sub-comp</h2 >
33
+ <p >
34
+ props: {{ props }}
35
+ <br />
36
+ attrs: {{ attrs }}
37
+ <br />
38
+ keys(attrs): {{ keys(attrs) }}
39
+ </p >
36
40
</template >
You can’t perform that action at this time.
0 commit comments