subcomponent emit update:modelValue event with an object twice the modelValue not change at second time
Version
3.2.26
Reproduction link
Steps to reproduce
- open
Link to minimal reproduction
- the data just change first time , atfter 3 sconds trigger emit twice, the data not change.
- this seems a bug like this
let a = { name: 'lucy' }; a.name = 'jay'; let b = a; a === b;
// true
What is expected?
the modelValue shuold change at second time.
What is actually happening?
the modelValue not change at second time.
the
test
object would need to be reactive() for this to work.
Although this is feasible, it is not in line with common sense. I don't understand why it should be reactive?
you emit the same object twice. So the parent doesn't nee to re-render - its still the same value, the same object.
And since the object is not reactive, the fact that you did change a property of the object isn't detected and can't trigger a re-render either.
That's pretty much the basic principle of Vue & Reactivity - changing plain objects isn't going to update your component's template, only reactive changes will.
so something like this never change view too.
const data = ref({
name: "initial",
desc: "This is description"
});
const obj = {name: 'first change'}
data.value = obj;
setTimeout(() => {
obj.name = 'second change'
// the view never change.
data.value = obj
}, 3000)