useLastChanged
记录最后更改的时间戳
示例
最后更改: 5 minutes ago (1741705039188)
使用方法
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
}
/**
* 记录最后更改的时间戳
*
* @see https://vueuse.org/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>
源码
贡献者
更新日志
v12.0.0-beta.1
on 11/21/2024