Sorting a list with a computed property
Ordering inside a v-for
with a filter is another thing that was considered for removal in Vue 1 and didn't survive in the current version.
Sorting a list with a computed property offers much more flexibility and we can implement any custom logic for ordering. In this recipe, you will create a list with some numbers within; we will sort the list using them.
Getting ready
To complete this recipe, you just require some familiarity with lists and computed properties; you can brush up on them with the Writing lists and Learning how to use computed properties recipes.
How to do it...
Let's write a list of the largest dams in the world.
First, we need an HTML table with three columns (Name
, Country
, Electricity
):
<div id="app"> <table> <thead> <tr> <th>Name</th> <th>Country</th> <th>Electricity</th> </tr> </thead> <tbody> </tbody> <...