跳到内容

useLastChanged

类别
导出大小
172 B
最后更改时间
3 周前

记录上次更改的时间戳

演示

上次更改时间: 5 分钟前 (1741578126990)

用法

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

默认情况下,更改会在下一个 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
}
/**
 * Records the timestamp of the last change
 *
 * @see https://vueuse.org.cn/useLastChanged
 */
export declare function useLastChanged(
  source: WatchSource,
  options?: UseLastChangedOptions<false>,
): ShallowRef<number | null>
export declare function useLastChanged(
  source: WatchSource,
  options: UseLastChangedOptions<true> | UseLastChangedOptions<boolean, number>,
): ShallowRef<number>

源代码

SourceDemoDocs

贡献者

Anthony Fu
IlyaL
James Garbutt
yaoyin
Jady Dragon
Alex Kozack

更新日志

v12.0.0-beta.1 于 2024/11/21
0a9ed - feat!: 移除 Vue 2 支持,优化 bundles 并清理 (#4349)

根据 MIT 许可证发布。