Skip to content

⬅️ Back to Table of Contents

📄 tryOnMounted

📊 Analysis Summary

Metric Count
🔧 Functions 1
📦 Imports 5

📚 Table of Contents

🛠️ File Location:

📂 packages/shared/tryOnMounted/index.ts

📦 Imports

Name Source
ComponentInternalInstance vue
Fn ../utils
nextTick vue
onMounted vue
getLifeCycleTarget ../utils

Functions

tryOnMounted(fn: Fn, sync: boolean, target: ComponentInternalInstance | null): void

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

Parameters:

  • fn any: No description
  • sync any: if set to false, it will run in the nextTick() of Vue
  • target any: No description
Raw JSDoc
/**
 * 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
 */

Calls:

  • getLifeCycleTarget (from ../utils)
  • onMounted (from vue)
  • fn
  • nextTick (from vue)
Code
export function tryOnMounted(fn: Fn, sync = true, target?: ComponentInternalInstance | null) {
  const instance = getLifeCycleTarget(target)
  if (instance)
    onMounted(fn, target)
  else if (sync)
    fn()
  else
    nextTick(fn)
}

Generated by Syntax Scribe