forked from vuejsdevelopers/vuejs-poster-shop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
95 lines (88 loc) · 4.08 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
86
87
88
89
90
91
92
93
94
95
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="referrer" content="never" />
<title>Vue.js Poster Shop</title>
<link rel="icon" href="public/favicon.ico" type="image/x-icon">
<!-- Fonts -->
<link href="https://fonts.googleapis.com/css?family=Luckiest+Guy" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Lato|Montserrat" rel="stylesheet">
<!-- CSS -->
<link rel="stylesheet" type="text/css" href="public/style.css">
</head>
<body>
<div id="app" v-cloak> <!-- works with css [v-cloak] display none, it prevent showing vue templates until the loading's finished -->
<div class="header">
<h1>Vue.js Poster Store</h1>
<!-- form in the Vue way: v-on:submit === action -->
<!-- add the .prevent modifier to the submit event->the submit event will no longer reload the page -->
<form class="searchbar" v-on:submit.prevent="onSubmit">
<!-- v-model to attach a data property to the input value -->
<input v-model="newSearch" type="text" placeholder="Search for posters">
<input type="submit" value="Search" class="btn">
</form>
</div>
<div class="main">
<div class="products">
<div v-if="loading">
Loading...
</div>
<div class="search-results" v-else>
Found {{ results.length }} results for search term {{ lastSearch }}.
</div>
<!-- Directives: all starts with 'v-', e.g.:
v-if -> a "if" statement
v-bind: -> binding a variable to a HTML attribute ->
<!-- v-for is Vue's iterate statement -->
<div class="product" v-for="(item,index) in items"> <!-- item and index are (v, k) to the list-->
<div>
<div class="product-image">
<!-- an example of v-bind -->
<img v-bind:src="item.link">
</div>
</div>
<div>
<h4 class="product-title">{{ item.title }}</h4>
<p>Price: <strong>{{ price | currency }}</strong></p>
<!-- v-on is responsible for event handling
after the colon: type of event e.g. click, mouseenter, etc
after the equal sign= javascript statement e.g. a data or method name -->
<button class="add-to-cart btn" v-on:click="addItem(index)">Add to cart</button>
</div>
</div>
<div id="product-list-bottom">
<div v-if="noMoreItems">No more items.</div>
</div>
</div>
<div class="cart">
<h2>Shopping Cart</h2>
<transition-group name="fade" tag="ul">
<li class="cart-item" v-for="item in cart" v-bind:key="item.id">
<div class="item-title">{{item.title}}</div>
<!-- using a Vue Filter to format the price -->
<span class="item-qty">{{item.price | currency}} x {{item.qty}}</span>
<button class="btn" v-on:click="inc(item)">+</button>
<button class="btn" v-on:click="dec(item)">-</button>
</li>
</transition-group>
<!-- Use Vue's transition for the Shopping Cart-->
<transition name="fade">
<div v-if="cart.length"> <!-- the inside div will appear only if "v-if" is true -->
<div>Total: {{ total | currency }}</div>
</div>
</transition>
<div v-if="cart.length===0" class="empty-cart"> <!-- The Vue's style if-else -->
No items in the cart.
</div>
</div>
</div>
</div>
<!-- Scripts -->
<script src="/reload/reload.js"></script>
<script src="node_modules/vue/dist/vue.js"></script>
<script src="node_modules/vue-resource/dist/vue-resource.js"></script>
<script src="node_modules/scrollmonitor/scrollMonitor.js"></script>
<script type="text/javascript" src="public/script.js"></script>
</body>
</html>