This repository has been archived by the owner on May 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
85 lines (84 loc) · 1.76 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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Vue.js - Basket sample</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
rel="stylesheet"
href="https://unpkg.com/bootstrap/dist/css/bootstrap.min.css"
/>
</head>
<body>
<div id="app">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th>Name</th>
<th>Quantity</th>
<th>Actions</th>
</tr>
</thead>
<tr
v-for="product in products"
v-bind:style="product.quantity === 0 ? 'background-color: rgba(255, 0, 0, 0.1)' : ''"
>
<td>{{ product.name }}</td>
<td>
<input
type="number"
v-model.number="product.quantity"
/>
</td>
<td>
<button
@click="product.quantity += 1"
class="btn btn-success"
>
Add
</button>
<button
@click="product.quantity -= 1"
class="btn btn-danger"
:disabled="product.quantity === 0"
>
Remove
</button>
</td>
</tr>
<tr class="info">
<td colspan="3">
<strong>
Total of inventory: {{ totalProducts }}
</strong>
</td>
</tr>
</table>
</div>
</div>
<script src="https://unpkg.com/vue"></script>
<script>
var App = new Vue({
el: "#app",
data: {
products: []
},
computed: {
totalProducts() {
return this.products.reduce((sum, product) => {
return sum + product.quantity;
}, 0);
}
},
created() {
fetch("https://api.myjson.com/bins/74l63")
.then(response => response.json())
.then(json => {
this.products = json.products;
});
}
});
</script>
</body>
</html>