Why ref wouldn't be unwrap when assign to a <ref>.value #13141
Unanswered
FoundTheWOUT
asked this question in
Help/Questions
Replies: 1 comment
|
import { reactive, ref, isRef, toRaw } from 'vue'
const name = ref(1)
const bar = ref(name)
const obj = reactive({})
const foo = ref()
obj.foo = name
foo.value = name
console.log(bar === name) // true: same ref
console.log(obj.foo) // 1: property read unwraps
console.log(toRaw(obj).foo === name) // true: underlying property holds name
console.log(isRef(foo.value)) // true: foo contains a ref
console.log(foo.value.value) // 1
name.value = 2
console.log(bar.value, obj.foo, foo.value.value) // 2 2 2For two variables that should point to the same ref, use I ran this example with Vue 3.5.14. The constructor's existing-ref check is in createRef, and the reactive API documentation describes property unwrapping. |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
ref will unwrapped when assign to a reactive obj, and will also unwrapped when passing it to the first argumrent of a ref.
All reactions