onUnmounted is called when there is no active component instance to be associated with.
Version
3.0.11
Reproduction link
Steps to reproduce
When I tried to use onUnmounted outside of setup, the console got a warning
What is expected?
I don't know what caused it
What is actually happening?
When I tried to use onUnmounted outside of setup, the console got a warning
onUnmounted is called when there is no active component instance to be associated with. Lifecycle injection APIs can only be used during execution of setup(). If you are using async setup(), make sure to register lifecycle hooks before the first await statement.
Vue2 + Composition API, it got the same problem in setup function
@chenguzhen87 Faced a similar problem, did you find a way to solve it?
Vue2 + Composition API, it got the same problem in setup function
I had the same problem when I used incorrect import (automatically added by IDE):
import { onMounted } from '@vue/composition-api/dist/vue-composition-api.js'
Solution:
import { onMounted } from '@vue/composition-api'
Vue2 + Composition API, it got the same problem in setup function
I had the same problem when I used incorrect import (automatically added by IDE):
import { onMounted } from '@vue/composition-api/dist/vue-composition-api.js'
Solution:
import { onMounted } from '@vue/composition-api'
K4T's issue also applied to my Vue 3 project. I'm using antfu's unplugin-auto-import. With this I don't need to import onMounted. But the IDE automatically added an import which created the issue.
I'm currently having the same problem (Vuejs (2.7.0) + Composition API). Did someone find a solution?
https://github.com/vuejs/core/issues/3671#issuecomment-1441575529
I realized, that in my case I was "double"-importing the Composition API, since it is already included in Vuejs 2.7.0 and yet I was importing it again in my 'main' script like this:
import VueCompositionAPI from '@vue/composition-api'
Vue.use(VueCompositionAPI)
(Of course, I also removed "@vue/composition-api": "^1.7.1"
from the dependencies
in the package.json
.)
Removing these lines solved the issue. It wasn't an obvious catch :-S