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>
- [Vuejs]-How to add custom property to vue input field
- [Vuejs]-Vue.js, vue-router and parameters/props
Source:stackexchange.com