-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(useTimeoutFn): add docs of useTimeoutFn
- Loading branch information
lmhcoding
committed
Sep 29, 2020
1 parent
b6e1f9b
commit 6890f7e
Showing
4 changed files
with
106 additions
and
0 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
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,25 @@ | ||
<template> | ||
<p>Is callback executed?: {{executed}}</p> | ||
<button @click="start">restart</button> | ||
<button @click="stop">stop</button> | ||
</template> | ||
<script> | ||
import { ref } from 'vue' | ||
import {useTimeoutFn} from 'v3hook' | ||
export default { | ||
setup () { | ||
const executed = ref(false) | ||
const { start, stop } = useTimeoutFn(() => { | ||
executed.value = true | ||
}) | ||
return { | ||
executed, | ||
start: () => { | ||
executed.value = false | ||
start() | ||
}, | ||
stop | ||
} | ||
} | ||
} | ||
</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 |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# ``useTimeoutFn`` | ||
|
||
--- | ||
|
||
|
||
|
||
用于在一段时间后执行回调 | ||
|
||
|
||
|
||
## API | ||
|
||
|
||
|
||
```typescript | ||
const { start, stop } = useTimeoutFn(fn, delay, immediate, clearEffectWhenStop) | ||
``` | ||
|
||
|
||
|
||
## Params | ||
|
||
| 参数名 | 描述 | 类型 | 默认值 | | ||
| ------------------- | --------------------------------------------- | -------- | ------ | | ||
| fn | 回调 | Function | | | ||
| delay | 定时时间 | number | | | ||
| immediate | 是否立即注册定时器 | boolen | true | | ||
| clearEffectWhenStop | 调用 ``stop`` 时是否停止内部的 ``watch`` 监听 | boolean | false | | ||
|
||
|
||
|
||
## Result | ||
|
||
| 参数名 | 描述 | 类型 | | ||
| ------ | --------------- | ---------- | | ||
| start | 开启/重启定时器 | () => void | | ||
| Stop | 停止定时器 | () => void | | ||
|
||
|
||
|
||
## Example | ||
|
||
|
||
|
||
<UseTimeoutFn/> | ||
|
||
|
||
|
||
## Code | ||
|
||
```vue | ||
<template> | ||
<p>Is callback executed?: {{executed}}</p> | ||
<button @click="start">restart</button> | ||
<button @click="stop">stop</button> | ||
</template> | ||
<script> | ||
import { ref } from 'vue' | ||
import {useTimeoutFn} from 'v3hook' | ||
export default { | ||
setup () { | ||
const executed = ref(false) | ||
const { start, stop } = useTimeoutFn(() => { | ||
executed.value = true | ||
}) | ||
return { | ||
executed, | ||
start: () => { | ||
executed.value = false | ||
start() | ||
}, | ||
stop | ||
} | ||
} | ||
} | ||
</script> | ||
``` | ||
|