getCurrentInstance type not correct
See original GitHub issueVersion
2.7.0
Steps to reproduce
vue2.7 getCurrentInstance type was not match vue3 & @vue/composition-api
export function getCurrentInstance(): { proxy: Component } | null {
return currentInstance && { proxy: currentInstance }
}
see:
- https://github.com/vuejs/composition-api/blob/main/src/runtimeContext.ts#L184
- https://github.com/vuejs/core/blob/main/packages/runtime-core/src/component.ts#L213
What is expected?
has correct type
What is actually happening?
not match
Issue Analytics
- State:
- Created a year ago
- Reactions:2
- Comments:8 (3 by maintainers)
Top Results From Across the Web
Vue 3: Is getCurrentInstance() deprecated? - Stack Overflow
Anything you use from that instance can technically break between any release types, since they are not subject to semver constraints.
Read more >getCurrentInstance in Vue 3 - Special Feature - Program Easily
getCurrentInstance in vue 3 is the special features used to get component instances. It won't work outside setup and lifecycle hooks.
Read more >API Reference - Vue.js
API Reference · Global API · Composition API · Options API · Built-ins · Single-File Component · Advanced APIs ...
Read more >Making the most out of Vue.js Injections - Abdelrahman Awad
This is a very important design decision, the return type of inject will always be nullable because there is always a possibility that...
Read more >Vue 2.7 getCurrentInstance() trying to get properties like $vuetify
I tested it out and it worked for me inside the onMounted callback, which implies that it's just not available before that point,...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@vue/composition-api
’s implementation is not the source of truth - 2.7 has intentional deviations from it.Only exposing
proxy
is intentional, because other properties on the internal instance is considered, well, internal. You should refactor any code that relies on anything other thanproxy
.This is necessary because relying on the internal instance properties when using Composition API is a sign that you are misusing it. It makes your code less reusable AND introduces risk of compatibility with future versions of Vue. We exposed
getCurrentInstance
mostly for official libraries that need additional internal access, not for userland application code. It was mistakenly documented in WIP v3 docs but is no longer considered a public API.Vue 3 will likely start showing warnings when you rely on properties other than
proxy
soon.@yyx990803 considering that this API is not public, how do you suggest to get the vue app instance (the one created with createApp() ) from any Vue component (created using <script setup>) ?
Currently I was using
getCurrentInstance().appContext.app