Skip to content

useLastChanged

类别
导出体积
143 B
上次更改
4 months ago

记录最后更改的时间戳

示例

最后更改: 5 minutes ago (1727403311824)

使用方法

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

默认情况下,更改将在下一个 tick 上记录 (使用 watch() 并且 flush: 'post')。如果你想立即记录更改,请将 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
}
/**
 * 记录最后更改的时间戳
 *
 * @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>

源码

源码演示文档

贡献者

Anthony Fu
一纸忘忧
yaoyin
Jady Dragon
Alex Kozack

更新日志

没有最近的更新日志