Why destructure a reactive obj also causing shallow reactive property unwraping #12282
-
Vue versionlatest Link to minimal reproductionSteps to reproduce👆 What is expected?reactive property not unwraping What is actually happening?https://vuejs.org/guide/essentials/reactivity-fundamentals.html#limitations-of-reactive
but not mention how destructure effect reactive property. IMO,primitive type property lose reactive could make sense, but reactive property being unwrap didn't, isn't it. System InfoNo response Any additional comments?No response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
This is called ref unwrapping an explained in the docs https://vuejs.org/api/reactivity-core.html#reactive
const count = ref(1)
const obj = reactive({ count })
// ref will be unwrapped
console.log(obj.count === count.value) // true
// it will update `obj.count`
count.value++
console.log(count.value) // 2
console.log(obj.count) // 2
// it will also update `count` ref
obj.count++
console.log(obj.count) // 3
console.log(count.value) // 3 |
Beta Was this translation helpful? Give feedback.
This is called ref unwrapping an explained in the docs
https://vuejs.org/api/reactivity-core.html#reactive