tryOnMounted
安全的 onMounted
。如果在组件生命周期内调用,则会调用 onMounted()
,否则只调用该函数。
用法
ts
import { tryOnMounted } from '@vueuse/core'
tryOnMounted(() => {
})
类型声明
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