Skip to content

useMounted

类别
导出体积
114 B
上次更改
2 months ago

在 ref 中表示组件是否已挂载。

示例

unmounted

使用方法

js
import { useMounted } from '@vueuse/core'

const isMounted = useMounted()

这本质上相当于:

ts
const isMounted = ref(false)

onMounted(() => {
  isMounted.value = true
})

类型声明

typescript
/**
 * Mounted state in ref.
 *
 * @see https://vueuse.org/useMounted
 */
export declare function useMounted(): ShallowRef<boolean, boolean>

源码

源码演示文档

贡献者

Anthony Fu
一纸忘忧
yanbowen

更新日志

0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
7966b - fix: The second argument in vue2.7 should be undefined (#3830)
ee297 - fix: compatible with vue2.7 (#3802)
2f66e - fix: hold the instance, close #3785, close #3795
1aab1 - fix: check for the current instance