跳到主要内容

tryOnBeforeUnmount

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

安全的 onBeforeUnmount。如果在组件生命周期内,则调用 onBeforeUnmount(),否则不执行任何操作。

用法

ts
import { 
tryOnBeforeUnmount
} from '@vueuse/core'
tryOnBeforeUnmount
(() => {
})

类型声明

ts
/**
 * Call onBeforeUnmount() if it's inside a component lifecycle, if not, do nothing
 *
 * @param fn
 * @param target
 */
export declare function 
tryOnBeforeUnmount
(
fn
:
Fn
,
target
?:
ComponentInternalInstance
| null,
): void

来源

源代码文档

贡献者

Anthony Fu
Ngheizit
Arthur Darkstone
SerKo
Anthony Fu
Doctorwu
qiang

更新日志

v14.0.0
a49a3 - fix: 更新参数类型以在生命周期中使用 ComponentInternalInstance (问题 #5060)
v12.3.0
59f75 - feat(toValue): 废弃 @vueuse/shared 中的 toValue,转而使用 Vue 的原生函数
0a9ed - feat!: 放弃对 Vue 2 的支持,优化打包并清理 (#4349)
v10.7.1
ce420 - fix: 修复 vue2 中的 tryOnMounted (问题 #3658)
v10.7.0
f2aeb - feat(tryOnMounted): 支持 target 参数 (问题 #3185)

根据 MIT 许可证发布。