-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
203 lines (198 loc) · 9.98 KB
/
index.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Vue</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<!-- Latest compiled and minified JavaScript -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</head>
<body>
<div class="container" id="app-demo" style="margin-top: 40px;">
<div class="row">
<div class="col-sm-8 col-sm-offset-2">
<div class="panel panel-info">
<div class="panel-heading">
<h3 class="panel-title">Vue Demo</h3>
<button type="button" class="btn btn-info pull-right" data-toggle="modal" data-target="#myModal"><i class="glyphicon glyphicon-plus"></i></button>
<form action="" method="POST" role="form">
<div class="form-group">
<!-- <label for="">Search</label> -->
<input type="text" class="form-control" id="" v-model="search" placeholder="Type content...">
</div>
</form>
</div>
<div class="panel-body">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Name</th>
<th>Age</th>
<th>Class</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr v-for="(person, index) in searchs">
<td>{{ person.name }}</td>
<td>{{ person.age }}</td>
<td>{{ person.class }}</td>
<td>
<button type="buton" v-on:click="updateStudent(index)" class="btn btn-info" data-toggle="modal" data-target="#myModalu"><i class="glyphicon glyphicon-pencil"></i></button>
<button type="buton" v-on:click="deleteStudent(index)" class="btn btn-danger"><i class="glyphicon glyphicon-trash"></i></button>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div id="myModal" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Add students</h4>
</div>
<div class="modal-body">
<form action="" method="POST" role="form" v-on:submit.prevent="addStudent">
<form action="" method="POST" role="form" v-on:submit.prevent="updateStudent">
<div class="form-group">
<label for="">Name</label>
<input type="text" class="form-control" v-model="student.name" required="" id="" placeholder="Name...">
</div>
<div class="form-group">
<label for="">Age</label>
<input type="number" class="form-control" v-model="student.age" id="" required="" placeholder="Age...">
</div>
<div class="form-group">
<label for="">Class</label>
<input type="text" class="form-control" v-model="student.class" required="" id="" placeholder="Class...">
</div>
<button type="submit" class="btn btn-primary" >Add</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" v-on:click="clearStudent" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<div id="myModalu" class="modal fade" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Update students</h4>
</div>
<div class="modal-body">
<form action="" method="POST" role="form" v-on:submit.prevent="updateStudent">
<div class="form-group">
<label for="">Name</label>
<input type="text" class="form-control" v-model="student.name" required="" id="" placeholder="Name...">
</div>
<div class="form-group">
<label for="">Age</label>
<input type="number" class="form-control" v-model="student.age" id="" required="" placeholder="Age...">
</div>
<div class="form-group">
<label for="">Class</label>
<input type="text" class="form-control" v-model="student.class" required="" id="" placeholder="Class...">
</div>
<button type="submit" class="btn btn-primary" >Update</button>
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" v-on:click="clearStudent" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<script src="https://unpkg.com/vue"></script>
<script>
var vue = new Vue({
el: '#app-demo',
data: {
search: '',
student: {
id: 0,
name: '',
age: '',
class: ''
},
people: [{
name: 'Vu Van A',
age: '20',
class: '12B'
}, {
name: 'Vu Van B',
age: '12',
class: '12A'
}, {
name: 'Vu Van C',
age: '14',
class: '12E'
}, {
name: 'Vu Van D',
age: '18',
class: '12D'
}, ],
},
methods: {
addStudent: function() {
if (this.people.push(this.student)) {
}
},
clearStudent: function() {
this.student = {
id: '',
name: '',
age: '',
class: ''
};
},
deleteStudent: function(index) {
delete this.people.splice(index,1);
},
updateStudent: function (index) {
this.student = this.people[index];
this.student.id = index;
},
},
computed: {
searchs: function (newsearch) {
var da = [];
var search = this.search;
if (this.search != '') {
this.people.forEach(function (item,index) {
if (item.name.toLowerCase().indexOf(search.toLowerCase()) > -1 ) {
console.log(item.name.toLowerCase());
da.push(item);
}
});
return da;
} else {
return this.people;
}
}
}
});
vue.people.push({
name: 'Vu Van E',
age: '22',
class: '12G'
});
</script>
</body>
</html>