1.0.0 • Published 3 years ago
vue-use-shared-tick v1.0.0
Vue useSharedTick
Vue 3 hook run function in same setInterval
Installation
use npm
npm install vue-use-shared-tick --saveuse yarn
yarn add vue-use-shared-tickuse pnpm
pnpm install vue-use-shared-tickUsage
run function per second
<script setup>
import { ref } from "vue"
import useSharedTick from "vue-use-shared-tick"
const time = ref(Date.now())
const onTick = (t) => {
time.value = t
}
useSharedTick(onTick)
</script>
<template>
<div>Current Timestamp: {{ time }}</div>
</template>run function per 3 second
useSharedTick(onTick, {tick: 3000})API
useSharedTick
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.
1.0.0
3 years ago