Now

Reactive custom timer with specified refresh rate

Parameters

import { useNow } from "vue-composable";

const now = useNow({
  refreshMs?: Number,
  sync?: Boolean,
  timeFn?: Function<Boolean>
});
ParametersTypeRequiredDefaultDescription
refreshMsNumberNo1000Refresh rate in milliseconds that the now gets updated
syncBooleanNotrueSync with the clock by the second
timeFnFunction<Boolean>NODate.nowFunction called when refresh the date

State

The useNow function exposes the following reactive state:

import { useNow } from "vue-composable";

const { now } = useNow();
StateTypeDescription
nowRef<Number>Current time

Methods

The useNow function exposes the following methods:

import { useNow } from "vue-composable";

const { remove } = useNow();
SignatureDescription
removeManually stop the now to be refreshed

Example

Created 1 seconds ago

Code

<template>
  <p>
    Created <b>{{ now }}</b> seconds ago
  </p>
</template>

<script>
import { useNow } from "vue-composable";

export default {
  name: "now",
  setup() {
    let i = 0;
    return useNow({
      timeFn: () => ++i
    });
  }
};
</script>