Back to Vueuse

useLastChanged

packages/shared/useLastChanged/index.md

14.3.0663 B
Original Source

useLastChanged

Records the timestamp of the last change

Usage

ts
import { useLastChanged } from '@vueuse/core'
import { nextTick } from 'vue'

const a = ref(0)
const lastChanged = useLastChanged(a)

a.value = 1

await nextTick()

console.log(lastChanged.value) // 1704709379457

By default the change is recorded on the next tick (watch() with flush: 'post'). If you want to record the change immediately, pass flush: 'sync' as the second argument.

ts
import { useLastChanged } from '@vueuse/core'

const a = ref(0)
const lastChanged = useLastChanged(a, { flush: 'sync' })

a.value = 1

console.log(lastChanged.value) // 1704709379457