[Vuejs]-Sort a list in vuejs

2👍

You’re probably better off using a computed property to sort your array into leagues. For example:

computed: {
  sortedGames() {
    return this.soccerlist.reduce((acc, game) => {
      if (acc[game.ligue]) acc[game.ligue].push(game);
      else acc[game.ligue] = [game];
      return acc;
    }, {})
  }
}

This will return you an object, with each game grouped by ligue. You can then v-for="ligue in sortedGames" and go from there.

👤Kwesi

Leave a comment