`modelValue` doesn't update value by `Array.push` if using assigning
Vue version
3.4.18
Link to minimal reproduction
Steps to reproduce
Click on button check
What is expected?
Displays an array with the value [1,2]
What is actually happening?
Displays an array with the value [1]
System Info
No response
Any additional comments?
No response
The reason is that the computed get
only updates on the next tick, after the parent has received the value, and re-rendered.
So value.value.push(2)
updates the old, empty array
I see how that can be counter-intuitive, but it's working as expected, from a technical perspective.
Solution: first, manipulate you array, then, assign the final result to the computed to trigger the emit.
The reason is that the computed
get
only updates on the next tick, after the parent has received the value, and re-rendered. Sovalue.value.push(2)
updates the old, empty arrayI see how that can be counter-intuitive, but it's working as expected, from a technical perspective.
Solution: first, manipulate you array, then, assign the final result to the computed to trigger the emit.
Thank you for your quick response!
Did I understand correctly that this behaviour only works when using array methods along with assignment?
An example
value.value.push(1);
value.value.push(2);
and
value.value = [1];
value.value.push(2);
have different results