File size: 374 Bytes
4d70170
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import type { Ref } from 'vue'
import { computed, ref } from 'vue'

export const reactiveNow = ref(Date.now())

setInterval(() => {
  reactiveNow.value = Date.now()
}, 100)

export function useTimeAgo(time: Ref<number>) {
  return {
    timeAgo: computed(() => {
      const diff = reactiveNow.value - time.value
      return `${Math.round(diff / 1000)}s ago`
    }),
  }
}