Skip to content

Commit

Permalink
fix(useMounted): hold the instance, close #3785, close #3795
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Feb 20, 2024
1 parent a086e8b commit 2f66e6f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
5 changes: 3 additions & 2 deletions packages/core/useMounted/index.ts
Expand Up @@ -9,10 +9,11 @@ import { getCurrentInstance, onMounted, ref } from 'vue-demi'
export function useMounted() {
const isMounted = ref(false)

if (getCurrentInstance()) {
const instance = getCurrentInstance()
if (instance) {
onMounted(() => {
isMounted.value = true
})
}, instance)
}

return isMounted
Expand Down
3 changes: 2 additions & 1 deletion packages/shared/tryOnMounted/index.ts
@@ -1,6 +1,7 @@
// eslint-disable-next-line no-restricted-imports
import { nextTick, onMounted } from 'vue-demi'
import { type Fn, getLifeCycleTarget } from '../utils'
import type { Fn } from '../utils'
import { getLifeCycleTarget } from '../utils'

/**
* Call onMounted() if it's inside a component lifecycle, if not, just call the function
Expand Down

0 comments on commit 2f66e6f

Please sign in to comment.