@u3u/vue-hooks
Version:
⚡️ Awesome Vue Hooks
23 lines (22 loc) • 690 B
JavaScript
import { ref, onMounted, onUnmounted } from '@vue/composition-api';
import dayjs from 'dayjs';
import relativeTime from 'dayjs/plugin/relativeTime';
dayjs.extend(relativeTime);
export default function useDate(d, timeout) {
if (d === void 0) { d = Date.now(); }
if (timeout === void 0) { timeout = 0; }
var date = ref(dayjs(d));
if (timeout) {
var timerId_1;
onMounted(function () {
timerId_1 = window.setInterval(function () {
date.value = dayjs(Date.now());
}, timeout);
});
onUnmounted(function () {
window.clearInterval(timerId_1);
});
}
return date;
}
export { dayjs };