Skip to content

usePrevious

类别
导出体积
260 B
上次更改
2 minutes ago

保存 ref 的先前值。

用法

ts
import { usePrevious } from '@vueuse/core'
import { ref } from 'vue'

const counter = ref('Hello')
const previous = usePrevious(counter)

console.log(previous.value) // undefined

counter.value = 'World'

console.log(previous.value) // Hello

类型声明

typescript
/**
 * 保存 ref 的前一个值。
 *
 * @see   {@link https://vueuse.org/usePrevious}
 */
export declare function usePrevious<T>(
  value: MaybeRefOrGetter<T>,
): Readonly<Ref<T | undefined>>
export declare function usePrevious<T>(
  value: MaybeRefOrGetter<T>,
  initialValue: T,
): Readonly<Ref<T>>

源码

源码文档

贡献者

Anthony Fu
一纸忘忧
Anthony Fu

更新日志

v10.0.0-beta.4 on 4/13/2023
4d757 - feat(types)!: rename MaybeComputedRef to MaybeRefOrGetter
10e98 - feat(toRef)!: rename resolveRef to toRef
v9.12.0 on 1/29/2023
e101f - feat: new function