-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheje04.html
76 lines (64 loc) · 1.92 KB
/
eje04.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Ejemplo 4</title>
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/vue"></script>
</head>
<body>
<main>
<table>
<thead>
<th>Nombre</th>
<th>Apellido</th>
</thead>
<tbody>
<tr v-for="(item , idx) in users">
<td>{{item.nombre}}</td>
<td>{{item.apellido}}</td>
</tr>
</tbody>
</table>
<form action="" @submit.prevent="createuser">
<input type="text" placeholder="Nombre" v-model="objUser.nombre">
<input type="text" placeholder="Apellidos" v-model="objUser.apellido">
<input type="submit" value="Guardar">
</form>
{{$data}}
</main>
</body>
<script type="text/javascript">
new Vue({
el:'main',
data:{
users:[
{'nombre':'Jona','apellido':'Teran'},
{'nombre':'Silvana','apellido':'Rodriguez'},
{'nombre':'Jona2','apellido':'teran2'},
],
objUser: {'nombre':null,'apellido':null}
},
methods:{
createuser(){
this.users.unshift(this.objUser);
this.orderUser;
this.objUser={'nombre':null,'apellido':null}
}
},
computed:{
orderUser(){
return this.users.sort(function(a,b){
if(a.nombre > b.nombre){
return 1;
}
if(a.nombre < b.nombre){
return -1;
}
return 0;
});
}
}
});
</script>
</html>