-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path13. reactivity.html
77 lines (54 loc) · 1.9 KB
/
13. reactivity.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
<!DOCTYPE html>
<html>
<head>
<title>Reactivity</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 d-flex flex-row">
<reactivity inline-template>
<div class="card p-4 alert-info mr-4" style="min-width: 400px;">
<h2>People</h2>
<ul>
<li v-for="person in people">
<div @click="toggle(person)">
{{ person.name }}
<span v-if="!person.expanded" class="float-right">+</span>
<span v-if="person.expanded" class="float-right">-</span>
</div>
<div v-if="person.expanded">
Age: {{ person.age }}
</div>
</li>
</ul>
</div>
</reactivity>
</div>
<script type="text/javascript">
Vue.component('reactivity', {
data() {
return {
people: [
{ name: 'Garry', age: 20, expanded: false},
{ name: 'Sophie', age: 24},
{ name: 'Chris', age: 12},
{ name: 'Mark', age: 32},
]
}
},
methods: {
toggle(person) {
// will only work for garry
person.expanded = !person.expanded
// will work for everybody
// this.$set(person, 'expanded', !person.expanded)
}
}
})
new Vue({
el: '#my-app'
})
</script>
</body>
</html>