Skip to content
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

help: Dependency injection at the plugin level #104

Closed
lewebsimple opened this issue Jun 8, 2020 · 2 comments
Closed

help: Dependency injection at the plugin level #104

lewebsimple opened this issue Jun 8, 2020 · 2 comments
Assignees

Comments

@lewebsimple
Copy link

📚 What are you trying to do? Please describe.
I'm trying to provide a value on the root Vue instance, and then inject this inside the various components / pages / layouts.

🔍 What have you tried?
I tried calling provide from setup() inside layouts/default.vueas was suggested in a couple of places, which kind of worked, but it doesn't look very clean to me (plus I'd need to have this code in every layout .... not very DRY)

I also tried creating a Nuxt plugin, which seemed like the proper way to do this, but the global provide / inject method described in the proposed RFC isn't available.

I also encountered the suggestion of assigning a new setup function to app, but this seems like it would break as soon as another plugin also assigns its own setup function.

ℹ️ Additional context
Having some kind of onSetup hook available in plugins or global provide would solve this kind of issue, people using vue-apollo-composable would have a cleaner way of providing the apollo client.

I'm not sure how dependency injection interacts with SSR and if provide could be used independently on the server and client Vue instance.

@danielroe
Copy link
Member

@lewebsimple Thanks for the report. Try onGlobalSetup in v0.9.2 - and let me know what you think 😃

@lewebsimple
Copy link
Author

Fantastic job !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants