Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Apply VueUse composables in Vue 3/Nuxt projects to replace custom implementations with battle-tested utilities.
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
references/useLastChanged.md
1---2category: State3---45# useLastChanged67Records the timestamp of the last change89## Usage1011```ts12import { useLastChanged } from '@vueuse/core'13import { nextTick } from 'vue'1415const a = ref(0)16const lastChanged = useLastChanged(a)1718a.value = 11920await nextTick()2122console.log(lastChanged.value) // 170470937945723```2425By 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.2627```ts28import { useLastChanged } from '@vueuse/core'2930const a = ref(0)31const lastChanged = useLastChanged(a, { flush: 'sync' })3233a.value = 13435console.log(lastChanged.value) // 170470937945736```3738## Type Declarations3940```ts41export interface UseLastChangedOptions<42Immediate extends boolean,43InitialValue extends number | null | undefined = undefined,44> extends WatchOptions<Immediate> {45initialValue?: InitialValue46}47export type UseLastChangedReturn =48| Readonly<ShallowRef<number | null>>49| Readonly<ShallowRef<number>>50/**51* Records the timestamp of the last change52*53* @see https://vueuse.org/useLastChanged54*/55export declare function useLastChanged(56source: WatchSource,57options?: UseLastChangedOptions<false>,58): Readonly<ShallowRef<number | null>>59export declare function useLastChanged(60source: WatchSource,61options: UseLastChangedOptions<true> | UseLastChangedOptions<boolean, number>,62): Readonly<ShallowRef<number>>63```64