Skip to content

refDefault

类别
导出体积
140 B
上次更改
2 months ago

将默认值应用于 ref。

用法

ts
import { 
refDefault
,
useStorage
} from '@vueuse/core'
const
raw
=
useStorage
('key')
const
state
=
refDefault
(
raw
, 'default')
raw
.
value
= 'hello'
console
.
log
(
state
.
value
) // hello
raw
.
value
=
undefined
console
.
log
(
state
.
value
) // default

类型声明

ts
/**
 * 将默认值应用于 ref。
 *
 * @__NO_SIDE_EFFECTS__
 */
export declare function 
refDefault
<
T
>(
source
:
Ref
<
T
| undefined | null>,
defaultValue
:
T
,
):
Ref
<
T
>

源码

源码文档

贡献者

Anthony Fu
一纸忘忧
SerKo

更新日志

d32f8 - refactor: add @__NO_SIDE_EFFECTS__ annotations to all pure functions (#4907)
0a9ed - feat!: drop Vue 2 support, optimize bundles and clean up (#4349)