跳到主要内容

tryOnMounted

分类
导出大小
164 B
上次更改
上个月

安全的 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

来源

源代码文档

贡献者

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

更新日志

v14.0.0
a49a3 - fix: 更新参数类型以在生命周期中使用 ComponentInternalInstance (问题 #5060)
v13.1.0
16551 - fix: 传递 target 给 getLifeCycleTarget (#4685)
0a9ed - feat!: 放弃对 Vue 2 的支持,优化打包并清理 (#4349)
v10.8.0
2f66e - fix(useMounted): 保持实例,关闭 #3785,关闭 #3795
v10.7.1
ce420 - fix: 修复 vue2 中的 tryOnMounted (问题 #3658)
v10.7.0
f2aeb - feat: 支持 target 参数 (#3185)

根据 MIT 许可证发布。