@@ -23,17 +23,17 @@ Provides a value that can be injected by descendant components.
23
23
` ` ` vue
24
24
<script setup>
25
25
import { ref, provide } from 'vue'
26
- import { fooSymbol } from './injectionSymbols'
26
+ import { countSymbol } from './injectionSymbols'
27
27
28
28
// provide static value
29
- provide('foo ', 'bar ')
29
+ provide('path ', '/project/ ')
30
30
31
31
// provide reactive value
32
32
const count = ref(0)
33
33
provide('count', count)
34
34
35
35
// provide with Symbol keys
36
- provide(fooSymbol , count)
36
+ provide(countSymbol , count)
37
37
</script>
38
38
` ` `
39
39
@@ -81,19 +81,19 @@ Injects a value provided by an ancestor component or the application (via `app.p
81
81
` ` ` vue
82
82
<script setup>
83
83
import { inject } from 'vue'
84
- import { fooSymbol } from './injectionSymbols'
84
+ import { countSymbol } from './injectionSymbols'
85
85
86
86
// inject static value without default
87
- const foo = inject('foo ')
87
+ const path = inject('path ')
88
88
89
89
// inject reactive value
90
90
const count = inject('count')
91
91
92
92
// inject with Symbol keys
93
- const foo2 = inject(fooSymbol )
93
+ const count2 = inject(countSymbol )
94
94
95
95
// inject with default value
96
- const bar = inject('foo ', 'default value ')
96
+ const bar = inject('path ', '/ default-path ')
97
97
98
98
// inject with function default value
99
99
const fn = inject('function', () => {})
@@ -103,6 +103,16 @@ Injects a value provided by an ancestor component or the application (via `app.p
103
103
</script>
104
104
` ` `
105
105
106
- - ** See also **
106
+ ## hasInjectionContext () < sup class = " vt-badge" data - text = " 3.3+" / > {#has-injection-context }
107
+
108
+ Returns true if [inject ()](#inject ) can be used without warning about being called in the wrong place (e .g . outside of ` setup() ` ). This method is designed to be used by libraries that want to use ` inject() ` internally without triggering a warning to the end user .
109
+
110
+ - ** Type **
111
+
112
+ ` ` ` ts
113
+ function hasInjectionContext(): boolean
114
+ ` ` `
115
+
116
+ * ** See also **
107
117
- [Guide - Provide / Inject ](/ guide / components / provide - inject )
108
118
- [Guide - Typing Provide / Inject ](/ guide / typescript / composition - api #typing - provide - inject ) < sup class = " vt-badge ts" / >
0 commit comments