I ran into this as well, and a lot of sample code out there from Vue 1.0 gives incorrect information on this topic. So I thought it might be helpful to post my findings in followup to Janspeed's correct answer on this topic.
For example, given an array defined in the data: block as follows:
data: {
event: { name: '', description: '', date: '' },
events: []
}
To set the entire array (in these examples, to the a local array var localEvents), these both work just fine, and you have a bit more flexibility with the second method:
this.events = localEvents; // assigns array, is reactive
this.events = localEvents.slice(0, localEvents.length); // assigns array, is reactive
You will see samples like this in tutorials, it doesn't work:
this.set$("events", localEvents)
It will result in this error:
Cannot set reactive property on undefined, null, or primitive value: events
Per: https://v2.vuejs.org/v2/guide/migration.html#Array-prototype-set-removed
However, Vue.set can be used to reactively add elements to an array. Therefore, given an array with length 3:
Vue.set(this.events, 4, newEvent); // adds newEvent to array reactively
this.events.splice(4, 1, newEvent); // also adds newEvent to array reactively
Of course, per the examples in the documentation, if you specify an index value corresponding to a existing array element, it will be replaced by your input object (newEvent in the examples above).
See: https://v2.vuejs.org/v2/guide/list.html#Replacing-an-Array
oldArr = newArr?