Skip to content

tryOnMounted

Category
Export Size
162 B
Last Changed
2 months ago

Safe onMounted. Call onMounted() if it's inside a component lifecycle, if not, just call the function

Usage

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

tryOnMounted(() => {

})

Type Declarations

typescript
/**
 * Call onMounted() if it's inside a component lifecycle, if not, just call the function
 *
 * @param fn
 * @param sync if set to false, it will run in the nextTick() of Vue
 * @param target
 */
export declare function tryOnMounted(fn: Fn, sync?: boolean, target?: any): void

Source

SourceDocs

Contributors

Anthony Fu
Ezra Ashenafi
Anthony Fu
Doctorwu
qiang
Connor Dooley
Nicholai Nissen

Changelog

v13.1.0 on
16551 - fix: pass target to getLifeCycleTarget (#4685)
v12.0.0-beta.1 on
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)
v10.8.0 on
2f66e - fix(useMounted): hold the instance, close #3785, close #3795
v10.7.1 on
ce420 - fix: fix tryOnMounted in vue2 (#3658)
v10.7.0 on
f2aeb - feat: support target arguement (#3185)

Released under the MIT License.

You. But 10x faster
The structured masterclass to help you leverage AI and build with an edge.
Join Early!