Skip to content

tryOnMounted

Category
Export Size
164 B
Last Changed
2 weeks ago

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

Usage

ts
import { 
tryOnMounted
} from '@vueuse/core'
tryOnMounted
(() => {
})

Type Declarations

ts
/**
 * 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
?:
ComponentInternalInstance
| null,
): void

Source

SourceDocs

Contributors

Anthony Fu
Arthur Darkstone
SerKo
Ezra Ashenafi
Anthony Fu
Doctorwu
qiang
Connor Dooley
Nicholai Nissen

Changelog

Pending for release...
a49a3 - fix: update parameter types to use ComponentInternalInstance in lifec… (#5060)
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.

Write AI-Powered code you can trust
Grab 45% off for AIDD Masterclass before it's gone.
Claim Now
00
hours
:
37
minutes
:
51
seconds
: