-
-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
feat(app.runWithContext): Support getCurrentInstance
#8594
Comments
The existing behavior is more flexible as it allows differentiating if you are running within a component + If anything, I would say The questions are: why do you need the |
Well, given that, the following code does something illegal - const app = v.createApp(
v.defineComponent({
setup() {
const instance = v.getCurrentInstance()
setTimeout(() => {
console.log(instance === app._instance) // true
})
},
})
)
app.mount('#app') One might even argue that In all seriousness my use case is pretty much the same as for plugins. Except plugin installs require boilerplate code and, well, installing the plugin. While most of the time I just need to know under which Vue app my code currently runs. Specifically, I need access to created App, not Actual usage of this for me involves classes and decorators, which would not make for a good example, however. |
Not at all, it's actually pretty useful. It's used to know if we are in the context of a component's setup.
I see. Then I think you should stick to plugins, it's better to not introduce yet another (and more obscure 😄 ) way of doing things. You get the current app directly on the plugin function's first argument. Unless there is something that cannot be achieved by plugins, this doesn't seem to be worth pursuing. If you find some, a well-defined use case would definitely help! |
What problem does this feature solve?
When
getCurrentInstance
is used withinapp.runWithContext
- top-level component instance should be returned (if it already exists). This should allow easier usage of Vue features outside components.This behavior can currently be 'emulated' with
app.provide
, but it feels like there should be no need for this workaround.runWithContext
was first introduced in #7451What does the proposed API look like?
The text was updated successfully, but these errors were encountered: