Skip to content

Commit

Permalink
fix(toRef): issue vuejs#855
Browse files Browse the repository at this point in the history
  • Loading branch information
Rigo-m committed Nov 24, 2021
1 parent 15564dd commit 47e3d47
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/reactivity/ref.ts
Expand Up @@ -2,6 +2,7 @@ import { RefKey } from '../utils/symbols'
import { proxy, isPlainObject, warn, def } from '../utils'
import { reactive, isReactive, shallowReactive } from './reactive'
import { readonlySet } from '../utils/sets'
import { set } from './set'

declare const _refBrand: unique symbol
export interface Ref<T = any> {
Expand Down Expand Up @@ -157,6 +158,8 @@ export function toRef<T extends object, K extends keyof T>(
const v = object[key]
if (isRef<T[K]>(v)) return v

if (!(key in object)) set(object, key, undefined)

return createRef({
get: () => object[key],
set: (v) => (object[key] = v),
Expand Down

0 comments on commit 47e3d47

Please sign in to comment.