Subscribe on changes!

onUnmounted is called when there is no active component instance to be associated with.

avatar
Apr 25th 2021

Version

3.0.11

Reproduction link

https://jsfiddle.net/posva/x/

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.

avatar
Apr 25th 2021

The onUnmounted hook can only be used inside the setup function

avatar
May 6th 2022

Vue2 + Composition API, it got the same problem in setup function

avatar
May 13th 2022

Vue2 + Composition API, it got the same problem in setup function

@chenguzhen87 Faced a similar problem, did you find a way to solve it?

avatar
May 31st 2022

+1

avatar
Jun 17th 2022

+1

avatar
Jun 24th 2022

+1

avatar
K4T
Jun 26th 2022

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'
avatar
Jun 29th 2022

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.

avatar
Oct 8th 2022

+1, the same problems...

avatar
Feb 13th 2023

+1

avatar
Feb 22nd 2023

+1

avatar
Feb 23rd 2023

I'm currently having the same problem (Vuejs (2.7.0) + Composition API). Did someone find a solution?

avatar
Feb 23rd 2023

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