inject() — vue Function Reference
Architecture documentation for the inject() function in apiInject.ts from the vue codebase.
Entity Profile
Dependency Diagram
graph TD e4409eb6_4a53_dc28_eb33_d7aa4790c424["inject()"] 83b69f04_ff47_67cf_7f1c_542b323e1eb5["apiInject.ts"] e4409eb6_4a53_dc28_eb33_d7aa4790c424 -->|defined in| 83b69f04_ff47_67cf_7f1c_542b323e1eb5 style e4409eb6_4a53_dc28_eb33_d7aa4790c424 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/v3/apiInject.ts lines 44–71
export function inject(
key: InjectionKey<any> | string,
defaultValue?: unknown,
treatDefaultAsFactory = false
) {
// fallback to `currentRenderingInstance` so that this can be called in
// a functional component
const instance = currentInstance
if (instance) {
// #2400
// to support `app.use` plugins,
// fallback to appContext's `provides` if the instance is at root
const provides = instance.$parent && instance.$parent._provided
if (provides && (key as string | symbol) in provides) {
// TS doesn't allow symbol as index type
return provides[key as string]
} else if (arguments.length > 1) {
return treatDefaultAsFactory && isFunction(defaultValue)
? defaultValue.call(instance)
: defaultValue
} else if (__DEV__) {
warn(`injection "${String(key)}" not found.`)
}
} else if (__DEV__) {
warn(`inject() can only be used inside setup() or functional components.`)
}
}
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does inject() do?
inject() is a function in the vue codebase, defined in src/v3/apiInject.ts.
Where is inject() defined?
inject() is defined in src/v3/apiInject.ts at line 44.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free