Skip to content

refDefault

类别
导出体积
107 B
上次更改
4 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

类型声明

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

源码

源码文档

贡献者

Anthony Fu
一纸忘忧

更新日志

没有最近的更新日志