useLastChanged
最終変更のタイムスタンプを記録します
デモ
最終変更日時: 5分前 (1732766052094)
使用方法
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
デフォルトでは、変更は次のティックで記録されます(`watch()` で `flush: 'post'` を使用)。変更をすぐに記録するには、2 番目の引数として `flush: 'sync'` を渡します。
ts
import { useLastChanged } from '@vueuse/core'
const a = ref(0)
const lastChanged = useLastChanged(a, { flush: 'sync' })
a.value = 1
console.log(lastChanged.value) // 1704709379457
型宣言
typescript
export interface UseLastChangedOptions<
Immediate extends boolean,
InitialValue extends number | null | undefined = undefined,
> extends WatchOptions<Immediate> {
initialValue?: InitialValue
}
/**
* Records the timestamp of the last change
*
* @see https://vueuse.dokyumento.jp/useLastChanged
*/
export declare function useLastChanged(
source: WatchSource,
options?: UseLastChangedOptions<false>,
): Ref<number | null>
export declare function useLastChanged(
source: WatchSource,
options: UseLastChangedOptions<true> | UseLastChangedOptions<boolean, number>,
): Ref<number>
ソース
貢献者
変更履歴
v12.0.0-beta.1
2024/11/21