I am using Vue JS to do viewmodel bindings. In my data
object I have an array of items that are sorted in ascending order (oldest to newest) and I'd like to keep it that way for code-based reasons.
var v = new Vue({
el: '#app',
data: {
items: [
{id: 51, message: 'first'},
{id: 265, message: 'second'},
{id: 32, message: 'third'}
],
}
}
However, when I display the array in the template I'd like to reverse the order so that it's descending (newest to oldest). I tried the following:
<ol>
<li v-for=item in items | orderBy -1 track-by=id>
This didn't work since the orderBy
filter seems to require a field name as its first argument.
Is there any way to accomplish this in the template using the v-for
syntax using the orderBy
filter? Or am I going to have to create a custom reverse
filter?