跳到主要内容

usePageLeave

分类
导出大小
707 B
上次更改
2 个月前

响应式状态,用于显示鼠标是否离开页面。

演示

{
  "isLeft": false
}

用法

ts
import { 
usePageLeave
} from '@vueuse/core'
const
isLeft
=
usePageLeave
()

组件用法

此函数还通过 @vueuse/components 包提供了一个无渲染组件版本。了解更多用法

vue
<template>
  <UsePageLeave v-slot="{ 
isLeft
}">
Has Left Page: {{
isLeft
}}
</UsePageLeave> </template>

类型声明

ts
/**
 * Reactive state to show whether mouse leaves the page.
 *
 * @see https://vueuse.org.cn/usePageLeave
 * @param options
 *
 * @__NO_SIDE_EFFECTS__
 */
export declare function 
usePageLeave
(
options
?:
ConfigurableWindow
,
):
ShallowRef
<boolean, boolean>
export type
UsePageLeaveReturn
=
ReturnType
<typeof
usePageLeave
>

来源

源代码演示文档

贡献者

Anthony Fu
SerKo
IlyaL
Fernando Fernández
Anthony Fu
vaakian X
lxhyl
wheat
Alex Kozack
Antério Vieira

更新日志

8c521 - feat(components)!: 重构组件并使其保持一致 (#4912)
v13.6.0
d32f8 - refactor: 为所有纯函数添加 @__NO_SIDE_EFFECTS__ 注释 (#4907)
v12.4.0
dd316 - feat: 尽可能在所有地方使用被动事件处理程序 (#4477)
0a9ed - feat!: 放弃对 Vue 2 的支持,优化打包并清理 (#4349)

根据 MIT 许可证发布。