-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Null
committed
Jul 30, 2024
1 parent
389b223
commit b7037f2
Showing
7 changed files
with
93 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<template> | ||
<div>useEventListener</div> | ||
</template> | ||
|
||
<script setup> | ||
import { useEventListener } from 'zhongjiayao_v3_hooks'; | ||
const cleanup = useEventListener('resize', () => { | ||
console.log('window resize cleanup'); | ||
}); | ||
cleanup(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,29 @@ | ||
# useEventListener | ||
|
||
<preview path="./demo/index.vue" title="基本使用" ></preview> | ||
方便地进行事件绑定,在组件 mounted 和 activated 时绑定事件,unmounted 和 deactivated 时解绑事件。 | ||
|
||
## 基本用法 | ||
|
||
<preview path="./demo/index.vue" title="基本使用"></preview> | ||
|
||
## 取消事件监听 | ||
|
||
<preview path="./demo/cleanup.vue" title="基本使用"></preview> | ||
|
||
## API | ||
|
||
### 参数 | ||
|
||
| 参数 | 说明 | 类型 | 默认值 | | ||
| -------- | -------------- | --------------- | ------ | | ||
| type | 监听的事件类型 | _string_ | - | | ||
| listener | 事件回调函数 | _EventListener_ | - | | ||
| options | 可选的配置项 | _Options_ | - | | ||
|
||
### Options | ||
|
||
| 参数 | 说明 | 类型 | 默认值 | | ||
| ------- | --------------------------------------------------------------- | ---------------------------------- | -------- | | ||
| target | 绑定事件的元素 | _EventTarget \| Ref\<EventTarget>_ | `window` | | ||
| capture | 是否在事件捕获阶段触发 | _boolean_ | `false` | | ||
| passive | 设置为 `true` 时,表示 `listener` 永远不会调用 `preventDefault` | _boolean_ | `false` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<template> | ||
<div>useEventListener</div> | ||
</template> | ||
|
||
<script setup> | ||
import { useEventListener } from 'zhongjiayao_v3_hooks'; | ||
const cleanup = useEventListener('resize', () => { | ||
console.log('window resize cleanup'); | ||
}); | ||
cleanup(); | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,29 @@ | ||
# useEventListener | ||
|
||
<preview path="./demo/index.vue" title="基本使用" ></preview> | ||
方便地进行事件绑定,在组件 mounted 和 activated 时绑定事件,unmounted 和 deactivated 时解绑事件。 | ||
|
||
## 基本用法 | ||
|
||
<preview path="./demo/index.vue" title="基本使用"></preview> | ||
|
||
## 取消事件监听 | ||
|
||
<preview path="./demo/cleanup.vue" title="基本使用"></preview> | ||
|
||
## API | ||
|
||
### 参数 | ||
|
||
| 参数 | 说明 | 类型 | 默认值 | | ||
| -------- | -------------- | --------------- | ------ | | ||
| type | 监听的事件类型 | _string_ | - | | ||
| listener | 事件回调函数 | _EventListener_ | - | | ||
| options | 可选的配置项 | _Options_ | - | | ||
|
||
### Options | ||
|
||
| 参数 | 说明 | 类型 | 默认值 | | ||
| ------- | --------------------------------------------------------------- | ---------------------------------- | -------- | | ||
| target | 绑定事件的元素 | _EventTarget \| Ref\<EventTarget>_ | `window` | | ||
| capture | 是否在事件捕获阶段触发 | _boolean_ | `false` | | ||
| passive | 设置为 `true` 时,表示 `listener` 永远不会调用 `preventDefault` | _boolean_ | `false` | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters