2
Ba late gentlemen, I’m beginner with Vi and I’m creating a list, but I’m having a hard time understanding how I will sort list by clicking on the column title follow example:
new Vue({
el: "#lista",
data:{
users :[
{nome: "Marcos Santos", email: "[email protected]"},
{nome: "Lennon Bueno", email: "[email protected]"}
]
}
})
<!DOCTYPE html>
<html lang="pt-br">
<head>
<meta charset="UTF-8">
<title>Vue 1</title>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<script src="https://unpkg.com/vue"></script>
</head>
<body>
<div class="container">
<div id="lista">
<table class="table table-bordered">
<tr>
<th><a href="#">Nome</a></th>
<th><a href="#">Email</a></th>
</tr>
<tr v-for="item in users">
<td>{{item.nome}}</td>
<td>{{item.email}}</td>
</tr>
</table>
</div> <!-- #lista -->
</div> <!-- .container -->
<script>
</script>
</body>
</html>
I would like when I click on name I sort by name, and by email I sort by email, where I start?
Just sort the data array. Your question is about how to sort, or how to run a function (like sorting) from one click?
– bfavaretto
@bfavaretto how to run ordering from cllick
– Lennon S. Bueno