跳到主要內容

usePageLeave

類別
匯出大小
625 B
上次變更
3 週前

響應式狀態,顯示滑鼠是否離開頁面。

範例

{
  "isLeft": false
}

用法

js
import { usePageLeave } from '@vueuse/core'

const isLeft = usePageLeave()

元件用法

此函數也透過 @vueuse/components 套件提供無渲染元件版本。 了解更多用法

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

類型宣告

typescript
/**
 * Reactive state to show whether mouse leaves the page.
 *
 * @see https://vueuse.dev.org.tw/usePageLeave
 * @param options
 */
export declare function usePageLeave(
  options?: ConfigurableWindow,
): ShallowRef<boolean, boolean>

原始碼

SourceDemoDocs

貢獻者

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

更新日誌

v12.4.0 on 1/10/2025
dd316 - feat: use passive event handlers everywhere is possible (#4477)
v12.0.0-beta.1 on 11/21/2024
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)

以 MIT 授權條款發布。