-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample_07.html
More file actions
87 lines (75 loc) · 2.87 KB
/
example_07.html
File metadata and controls
87 lines (75 loc) · 2.87 KB
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
<html>
<head>
<title>Vue.js Example 07</title>
<link rel="stylesheet" type="text/css" href="bootstrap-3.3.7-dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="styles/site.css">
<script src="lib/vue@2.2.1.js"></script>
</head>
<body>
<div id="app">
<div class="panel-group">
<div class="panel panel-default card">
<div class="panel-heading">
<h2>We Serve:</h2>
</div>
<div class="panel-body">
<ul class="list-group">
<pizza-item v-for="pizza in list" v-bind:type="pizza.type"></pizza-item>
</ul>
</div>
</div>
</div>
</div>
<script>
/**
Let's take things a step forward.
We have a list of pizzas: margherita, hawaii, potato
Each pizza will be displayed by our "pizza-item" component.
To do that, our "pizza-item" has a property: "type".
To bind the type of pizza to our "pizza-item" type property we use:
v-bind:type="pizza.type"
If you don't write v-bind then Vue will treat "pizza.type" as plain text and not
figure out that the type should be defered from our list.
¯\_(ツ)_/¯
Each "pizza-item" component also has a button for adding more pizza !!
When we click the button it will increase the amount by 1.
*/
Vue.component('pizza-item', {
props: ['type'],
template: `<li class="list-group-item">
<input type="button" class="btn btn-default" v-on:click="add" value="+">{{ type }}</input>
<span class="badge">{{amount}}</span>
</li>`,
data: function () {
return {
amount: 0
}
},
methods: {
add: function () {
this.amount += 1;
}
}
});
new Vue({
el: '#app',
data: function () {
return {
list: [
{ type: 'margherita' },
{ type: 'hawaii' },
{ type: 'potato'}
]
}
}
});
</script>
</body>
</html>
<!--
Example 07:
- Create a list.
- Add a decrease button
- When clicking the amount decrease by 1
- If the amount is 0, you can not decrease it anymore
->