Skip to content
Discussion options

You must be logged in to vote

You should usually avoid it as the store could be instantiated outside of a component lifecycle and therefore never trigger the function passed to onMounted().

You should also guard it:

import { getCurrentInstance } from 'vue'

// ...
if (getCurrentInstance()) {
  onMounted(() => {
  })
}

An equivalent to onUnmounted() for stores is onScopeDispose() (https://vuejs.org/api/reactivity-advanced.html#onscopedispose) but this only triggers if you dispose of the store with store.$dispose()

Replies: 5 comments 2 replies

Comment options

You must be logged in to vote
0 replies
Answer selected by posva
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@posva
Comment options

posva Mar 4, 2024
Maintainer

Comment options

You must be logged in to vote
1 reply
@mrleblanc101
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
6 participants
Converted from issue

This discussion was converted from issue #1506 on August 01, 2022 13:00.