-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow defining optional inject dependency with default values #6097
Comments
Ditto on this request. What I typically find myself doing is overriding the injected property as data in order to provide a default: inject: [
'foo'
],
data () {
return {
foo: this.foo || 'default'
}
} |
I'm also +1 for this feature. Currently I have components that are nested within each other and parents provide info to the children. The warning always pops up for the root component as it doesn't have a provider for the injected property. Specific use case: nested layout splitters. |
I'm working on a component library that utilizes provide and inject for certain components to behave/look slightly differently when in the context of another component of the library. Since our components are used by other engineers for development, warnings that the injection was not found keeps showing up in their environment. Would love this feature to be implemented. And to add to it, as mentioned in #6137, I'd like to see a |
* close #6097: Allow defining optional inject dependency with default values Document changes in inject definition for feature #6097 * reformatted description of inject options * further clarification of inject options description
What problem does this feature solve?
In case of components that can work both as standalone and as children, it would be nice to be able to provide default values for the not provided dependencies.
It would also avoid the warning for missing inject in case this is one of the expected use case.
What does the proposed API look like?
inject: Array | { [key: string]: string | Symbol | { name: string | Symbol, default: any } }
The text was updated successfully, but these errors were encountered: