Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ckaznable/vue-use-shared-tick
Vue 3 hooks run function in same setInterval
https://github.com/ckaznable/vue-use-shared-tick
typescipt vue vue-hooks vue-hooks-library vue-typescript vue3
Last synced: about 2 months ago
JSON representation
Vue 3 hooks run function in same setInterval
- Host: GitHub
- URL: https://github.com/ckaznable/vue-use-shared-tick
- Owner: ckaznable
- License: mit
- Created: 2023-01-07T08:02:06.000Z (almost 2 years ago)
- Default Branch: master
- Last Pushed: 2023-01-09T02:38:02.000Z (almost 2 years ago)
- Last Synced: 2024-10-16T11:03:27.240Z (2 months ago)
- Topics: typescipt, vue, vue-hooks, vue-hooks-library, vue-typescript, vue3
- Language: TypeScript
- Homepage: https://www.npmjs.com/package/vue-use-shared-tick
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[![npm version](https://img.shields.io/npm/v/vue-use-shared-tick?color=g)](https://www.npmjs.com/package/vue-use-shared-tick)
# Vue useSharedTick
Vue 3 hook run function in same `setInterval`
## Installation
use npm
```
npm install vue-use-shared-tick --save
```use yarn
```
yarn add vue-use-shared-tick
```use pnpm
```
pnpm install vue-use-shared-tick
```## Usage
run function per second
```vue
import { ref } from "vue"
import useSharedTick from "vue-use-shared-tick"const time = ref(Date.now())
const onTick = (t) => {
time.value = t
}useSharedTick(onTick)
Current Timestamp: {{ time }}```
run function per 3 second
```js
useSharedTick(onTick, {tick: 3000})
```## API
### useSharedTick
```js
useSharedTick(handler: (t: number)=>void, param)
```### Handler
| Param | Type | Description |
|---|---|---|
|timestamp|`number`|current timestamp|### Parameter
| Field | Type | Default | Requirement |Description |
|---|:---:|:---:|:---:|:---:|
| tick | `number` | `1000` | `No` | Running interval time |
| runOnTabVisible | `boolean` | `false` | `No` | when true will pause/start interval if `visibilitychange` event dispatched |## License
The files included in this repository are licensed under the MIT license.