-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample_09.html
More file actions
77 lines (69 loc) · 2.86 KB
/
example_09.html
File metadata and controls
77 lines (69 loc) · 2.86 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
<html>
<head>
<title>Vue.js Example 09</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" class="example09">
<div class="panel-group">
<div class="panel panel-default card">
<div class="panel-heading">
<h2>Pizza Ingredients (Buy):</h2>
</div>
<div class="panel-body">
<ul class="list-group">
<pizza-ingredient v-for="ingredient in ingredients" v-bind:ingredient="ingredient"></pizza-ingredient>
</ul>
</div>
</div>
</div>
</div>
<script>
/**
How we can style our components dynamically ?
So based on the properties it will change its appearance.
Remember "Computed" ? ;)
We bind our computed field to the class attribute in our component's HTML.
*/
Vue.component('pizza-ingredient', {
template: '<li class="list-group-item ingredient" v-bind:class="stylingOptions">{{ingredient.name}} ({{ingredient.quantity}})</li>',
props: ['ingredient'],
computed: {
stylingOptions: function () {
return {
disabled: this.ingredient.status === 'cart'
}
}
}
});
var app = new Vue({
el: '#app',
data: function () {
return {
ingredients: [
{ name: 'Strong bread flour', quantity: '250g', status: 'cart'},
{ name: 'Dried yeast', quantity: '2 teaspoons' , status: 'buy'},
{ name: 'Caster sugar', quantity: '1 teaspoon' , status: 'buy'},
{ name: 'Olive oil', quantity: '2 g' , status: 'buy'},
{ name: 'Garlic', quantity: '2 cloves' , status: 'cart'},
{ name: 'Tin of chopped tomatoes', quantity: '1 x 400 g' , status: 'buy'},
{ name: 'Sprigs of fresh basil', quantity: 'a dash' , status: 'cart'},
]
};
}
});
</script>
</body>
<!--
Example 09:
Create a list of Pizzas
Each Pizza should have:
- Name
- Price
- Picture
- sale (true / false)
if the pizza is on sale:
- Name should be bold
-->