Skip to content

Commit 1aab1f2

Browse files
committed
fix(useMounted): check for the current instance
1 parent 5478f78 commit 1aab1f2

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

packages/core/useMounted/index.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// eslint-disable-next-line no-restricted-imports
2-
import { onMounted, ref } from 'vue-demi'
2+
import { getCurrentInstance, onMounted, ref } from 'vue-demi'
33

44
/**
55
* Mounted state in ref.
@@ -10,9 +10,11 @@ import { onMounted, ref } from 'vue-demi'
1010
export function useMounted() {
1111
const isMounted = ref(false)
1212

13-
onMounted(() => {
14-
isMounted.value = true
15-
})
13+
if (getCurrentInstance()) {
14+
onMounted(() => {
15+
isMounted.value = true
16+
})
17+
}
1618

1719
return isMounted
1820
}

0 commit comments

Comments
 (0)