onomad 2.0.2 → 2.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/vue/TimeAgo-ajdd20a8.vue +35 -0
- package/dist/vue/index.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, onMounted, onUnmounted, watch } from 'vue';
|
|
3
|
+
import { timeago } from '../onomad';
|
|
4
|
+
|
|
5
|
+
const props = withDefaults(defineProps<{
|
|
6
|
+
date: Date | string;
|
|
7
|
+
updateInterval?: number;
|
|
8
|
+
}>(), {
|
|
9
|
+
updateInterval: 60000
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const formattedTime = ref(timeago(new Date(props.date)));
|
|
13
|
+
let intervalId: ReturnType<typeof setInterval> | null = null;
|
|
14
|
+
|
|
15
|
+
const updateTime = () => {
|
|
16
|
+
formattedTime.value = timeago(new Date(props.date));
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
onMounted(() => {
|
|
20
|
+
intervalId = setInterval(updateTime, props.updateInterval);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
onUnmounted(() => {
|
|
24
|
+
if (intervalId) {
|
|
25
|
+
clearInterval(intervalId);
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
// Update immediately if date prop changes
|
|
30
|
+
watch(() => props.date, updateTime);
|
|
31
|
+
</script>
|
|
32
|
+
|
|
33
|
+
<template>
|
|
34
|
+
<span>{{ formattedTime }}</span>
|
|
35
|
+
</template>
|
package/dist/vue/index.js
CHANGED