Skip to content

useLastChanged

Category
Export Size
143 B
Last Changed
6 months ago

记录最后更改的时间戳

Demo

最后更改: 5 minutes ago (1730363784697)

使用方法

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>

Source

SourceDemoDocs

贡献者

Anthony Fu
丶远方
yaoyin
Jady Dragon
Alex Kozack

变更日志

No recent changes

Released under the MIT License.