[Vuejs]-Arrange data (comments) based on the most votes with vue.js

2👍

You could check the Vue documentation itself, where your use case is properly described. See here.

Basically you have to:

1 – define a computed property performing the sorting, for example:

computed: {
    sortedComments: function () {
      return this.comments.sort((a, b) => parseInt(a.votes) - parseInt(b.votes));
    }
}

2 – iterate over the computed property:

<li v-for="n in sortedComments">{{ n }}</li>

Leave a comment