Skip to content

Instantly share code, notes, and snippets.

@enwin
Created October 27, 2019 10:39
Show Gist options
  • Save enwin/e1db87c8ebd99be73648a330563b97ed to your computer and use it in GitHub Desktop.
Save enwin/e1db87c8ebd99be73648a330563b97ed to your computer and use it in GitHub Desktop.
Update an array of objects while keeping it reactive for vue
export default (vueArray, data) => {
data.forEach((entry, index) => {
if (!vueArray[index]) {
vueArray.push(entry);
return;
}
const previousEntry = vueArray[index];
vueArray.splice(index, 1, {
...previousEntry,
...entry
});
});
vueArray.splice(data.length);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment