-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path11. filters.html
88 lines (62 loc) · 2.02 KB
/
11. filters.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
<!DOCTYPE html>
<html>
<head>
<title>Filters</title>
<script type="text/javascript" src="https://vuejs.org/js/vue.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" integrity="sha384-rwoIResjU2yc3z8GV/NPeZWAv56rSmLldC3R/AZzGRnGxQQKnKkoFVhFQhNUwEyJ" crossorigin="anonymous">
</head>
<body>
<div id="my-app" class="container pt-4">
<filters inline-template>
<div class="card p-4">
<div class="alert alert-danger">
Filters <strong>not</strong> as in searches.
</div>
<h2 class="mt-4 mb-4">They let you manipulate data</h2>
<ul>
<li v-for="name in names">From {{ name }} into -> {{ name | backwards }}</li>
</ul>
<div class="alert alert-info mt-4">
If you want to "filter" data - as in an array of results, then you use "computed properties" to return the results, such as only showing the boys.
</div>
<ul>
<li v-for="name in boys">{{ name }}</li>
</ul>
</div>
</filters>
</div>
<script type="text/javascript">
Vue.component('filters', {
data() {
return {
names: [
'Garry',
'John',
'Selma',
'Helen',
]
}
},
filters: {
backwards(string) {
return string.split('').reverse().join('')
},
},
computed: {
boys() {
let boys = [];
this.names.forEach(name => {
if (['Garry', 'John'].indexOf(name) !== -1) {
boys.push(name);
}
})
return boys;
}
}
})
new Vue({
el: '#my-app'
})
</script>
</body>
</html>