tryOnMounted
Commons
stable
Call a function when the component mounts, or immediately when called outside a Vue component lifecycle. Falls back to nextTick when sync is false and no lifecycle target is found.
API
Signature
Full TypeScript signature sourced from the util file.
API
Parameters
Input parameters accepted by this util.
- fnrequiredTFn
- The function to execute. Called with `onMounted()` when a lifecycle instance is active, or called synchronously/via nextTick outside one.
- syncbooleantrue
- When true (default), fn is called synchronously outside a component. When false, fn is deferred with `nextTick`.
- targetany
- Optional Vue component instance to bind the lifecycle to, forwarded to `onMounted(fn, target)` when provided.
API
Return value
The value returned by this util.
- No return value. Side-effectful: schedules or calls fn.
Usage
Examples
Ready-to-paste usage snippets.
Safe use inside and outside a component