Im a bit new to JS and vue and am not quite sure if i understood the documentation correctly. it says:
Due to the limitations of modern JavaScript (and the abandonment of Object.observe), Vue cannot detect property addition or deletion. Since Vue performs the getter/setter conversion process during instance initialization, a property must be present in the data object in order for Vue to convert it and make it reactive.
does this include normal arrays as well, or do elements in arrays not count as "properties" in javascript? I wish to do state.array.push(data) to an array. Is this the correct way to do it?
Regarding the docs:
Due to limitations in JavaScript, Vue cannot detect the following changes to an array:
Vue will keep reactivity (Array change detection) when using:
So the answer to the question is state.array.push reactive ? is Yes
state.array.push(data)
is correct.
What the documentation says is:
// If initially you have an object like this
state = {
obj:{
key1: ["dummy"]
}
};
// this will be reactive
state.obj.key1.push("dummy2");
// however if you add a new property to the object like this,
// then whatever you do with obj['key2'] will not be reactive
state.obj['key2'] = ["dummy"];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With