tryOnMounted
安全的 onMounted
。如果在元件生命週期內,則呼叫 onMounted()
,否則直接呼叫函式
用法
js
import { tryOnMounted } from '@vueuse/core'
tryOnMounted(() => {
})
類型宣告
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