Skip to content

usePrevious

保存 ref 的前一个值。

¥Holds the previous value of a ref.

示例

counter: 1

previous: 0

用法

¥Usage

ts
import { 
usePrevious
} from '@vueuse/core'
import {
shallowRef
} from 'vue'
const
counter
=
shallowRef
('Hello')
const
previous
=
usePrevious
(
counter
)
console
.
log
(
previous
.
value
) // undefined
counter
.
value
= 'World'
console
.
log
(
previous
.
value
) // Hello