-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
Provide/Inject in functional components #5194
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
Comments
This has been implemented in #5204, will be merged when we release 2.3. |
@yyx990803 |
@Kingwl @yyx990803 Are you sure this is working now? Finally got around to using this in my component, but The button component is nested under the editor component and so it should be receiving the provided properties. I can even verify the props in the editor component ( |
@alidcastano if it's not working, please open a dedicated issue with proper reproduction. |
Hi Evan, I think there is a problem with Vue 2.6.6 and provide/inject. Lets say that we have one {
name: 'page',
provide() {
return {
pageMode: this.mode
}
},
props: {
mode: {
type: String
}, Also we have one {
name: 'field',
functional: true,
inject: ['pageMode']
} Working: When
Broken: When
I got: vue.js?b2d9:634 [Vue warn]: Injection "pageMode" not found Andrey |
I understand that functional components are instanceless, but given that they still have access to the parent context, wouldn't it make sense to also give them access to provided ancestor properties?
For example, I created vue-mobiledoc-editor. In the current version, I used a shared Vue instance that I passed to the editor and button components so that they could communicate with each other; and since there were various types of buttons (e.g. section, markup, and link buttons), I made the component functional.
I want to upgrade the code to using provide/inject since not having to pass the shared instance to every component makes the code more maintainable and will also make it easier to create multiple editor instances. However, it is not possible to inject exposed ancestor data and methods in functional components. If there is no specific reason for this, I'd like to make this a feature request.
The text was updated successfully, but these errors were encountered: