[Vuejs]-Sorting array from vuex store (infinite render warning)

6👍

sort will mutate the array in place. You can create a local copy of the item list in your component and then sort the copy to avoid the side effect:

itemList() {
  if(this.currentItemList != undefined) {
    var localItemList = JSON.parse(JSON.stringify(this.currentItemList))
    return localItemList.sort(...)
👤Psidom

7👍

With this.currentItemList.sort you are mutating reactive data in computed properties – that will trigger the component always to rerender … Do not mutate data in computed properties. Instead make sure to sort on a copy of your array: this.currentItemList.slice().sort(...)

👤Jns

Leave a comment