Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

testy's avatar

Vue - Is there an way in v-for to orderBy $index

I need to to order an list with v-for by $index. So that the last entry on my array comes first.

0 likes
2 replies
infernobass7's avatar

I think at the moment there is not a way to sort by the $index using orderBy. However, if you have an attribute in the list that you could use to reverse the order you can use the following.

v-for="item in list | orderBy 'attr' -1"

Check out this documentation http://vuejs.org/api/#orderBy

I attempted with the $index but it doesn't seem to work. https://jsfiddle.net/s7mqscst/

zeratulmdq's avatar

I'd have an ID inside every array item and orderBy it. Or you can have a computed property like so:

computed: {
    reverse: function() {
        return this.users.reverse();
    }
}

and do a v-for="user in reverse" instead of "user in users"

2 likes

Please or to participate in this conversation.