Skip to content

useLastChanged

记录最后一次更改的时间戳

¥Records the timestamp of the last change

示例

Last changed: 5 minutes ago (1730535909609)

用法

¥Usage

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

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

a.value = 1

await nextTick()

console.log(lastChanged.value) // 1704709379457

默认情况下,更改记录在下一个刻度(watch()flush: 'post')。如果你想立即记录更改,请传递 flush: 'sync' 作为第二个参数。

¥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

类型声明

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.org/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>

源代码

源代码示例文档

变更日志

No recent changes

VueUse 中文网 - 粤ICP备13048890号