Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vue.js best way to update entire array

Tags:

What is the best way to update the entire observed array and trigger a rerender in vue.js without having to iterate an push all the items?

I have read the documentation here: https://vuejs.org/v2/guide/list.html#Replacing-an-Array

But it doesn't make sense to me having to filter, concat or slice just to update the array? There must be something I missed?

like image 909
Janspeed Avatar asked Aug 17 '17 08:08

Janspeed


1 Answers

As suggested I will repond to this myself to help anyone in the same predicament.

oldArr = newArr

should still work (thank you choasia. Even though it is somewhat unclear in the vue.js documentation. Replacing the entire array will not fall under the caveats mentioned there (thank you Roy J ).

One option might also be to to empty the array and then push the new one like:

yourArray.push(... yourNewArray)

Thank you reiner

like image 86
Janspeed Avatar answered Sep 21 '22 07:09

Janspeed