1+ <!-- https://www.vuemastery.com -->
2+ < html >
3+ < head >
4+ < script src ="https://unpkg.com/vue "> </ script >
5+ < link href ="./assets/style.css " rel ="stylesheet " type ="text/css ">
6+ < link rel ="stylesheet " href ="https://use.fontawesome.com/releases/v5.8.1/css/all.css ">
7+ </ head >
8+ < body >
9+ < div id ="app ">
10+ < div class ="nav-bar "> </ div >
11+ < div class ="product ">
12+ < div class ="product-image ">
13+ < img v-bind:src ="image " :title ="imageTitle ">
14+ <!-- Attribute Shorthands -->
15+ <!-- :src, :alt, :title, :class, :style, :disabled -->
16+ </ div >
17+
18+ < div class ="product-info ">
19+ <!-- Binding -->
20+ < h1 > {{ product }}</ h1 >
21+
22+
23+ <!-- Conditionals -->
24+ < div >
25+ <!-- Falsey will not include in DOM -->
26+ < p v-if ="inventory > 10 "> In Stock</ p >
27+ < p v-else-if ="inventory "> Almost sold out</ p >
28+ < p v-else > Out of Stock</ p >
29+
30+ <!-- Render with display: none -->
31+ < p v-show ="inventory < 0 "> Wuuk?</ p >
32+ </ div >
33+
34+
35+ <!-- Events -->
36+ < button
37+ v-on:click ="cart++; inventory-- "
38+ :disabled ="!inventory "
39+ :class ="{disabledButton: inventory ? false : true} "
40+ >
41+ <!-- Method: addToCart -->
42+ Add to Cart
43+ </ button >
44+
45+ < div class ="cart ">
46+ {{cart}}
47+ < i class ="fas fa-shopping-cart "> </ i >
48+ </ div >
49+
50+
51+ <!-- Loops -->
52+ < div v-for ="variant in variants "
53+ :key ="variant.id "
54+ class ="color-box "
55+ :style ="{backgroundColor: variant.color} "
56+ @mouseover ="setImage(variant.color) ">
57+ </ div >
58+ </ div >
59+ </ div >
60+ </ div >
61+ </ body >
62+ </ html >
63+
64+
65+ < script type ="text/javascript ">
66+ const app = new Vue ( {
67+ el : '#app' ,
68+ data : {
69+ product : 'Socks' ,
70+ image : './assets/socks-green.jpg' ,
71+ imageTitle : 'Green Socks' ,
72+ variants : [
73+ { id : 1 , color : 'green' } ,
74+ { id : 2 , color : 'blue' }
75+ ] ,
76+ inventory : 3 ,
77+ cart : 0
78+ } ,
79+ methods : {
80+ addToCart ( ) {
81+ this . cart ++ ;
82+ this . inventory -- ;
83+ } ,
84+ setImage ( color ) {
85+ console . log ( 'Vue object with data and methods' , this ) ;
86+ this . image = `./assets/socks-${ color } .jpg` ;
87+ }
88+ } ,
89+ computed : {
90+ title ( ) {
91+ // Return values are cached
92+ return this . product . toUpperCase ( ) ;
93+ }
94+ }
95+ } ) ;
96+ console . log ( 'Modify data directly from the console with `app.product = "Shoes";`' ) ;
97+ </ script >
98+
99+
100+ <!-- livereload -->
101+ < script > document . write ( '<script src="http://' + ( location . host || 'localhost' ) . split ( ':' ) [ 0 ] + ':35729/livereload.js?snipver=1"></' + 'script>' ) </ script >
0 commit comments