myVueFirstProject
v-bind:,v-for,v-on@,v-if,v-else,v-show,
by Divya Manu
HTML
<html>
<body>
<div id="app">
<div class="product">
<div class="product-image">
<img v-bind:src="image" />
<!--short of v-bind is : -->
</div>
<div class="product-info">
<h1> {{product}} </h1>
<p v-if="inStock"> In Stock </p>
<!--V-show will render DOM -->
<p v-else> Out Of Stock </p>
<ul>
<li v-for="detail in details">{{detail}}</li>
</ul>
<div class="divcontainer">
<div v-for="color in colors" :key="color.Id">
<div class="color-box" :style="{backgroundColor:color.name}" @mouseover="updateProduct(color.image)">
<!-- <p @mouseover="updateProduct(color.image)">{{color.name}} </p>@ is short for v-on -- @keyup.enter where .enter is a modifier -->
</div>
</div>
</div>
<div>
<button v-on:click="addToCart">Add to Cart</button>
<div class="cart">
<input v-model="cart">
<p class="direct">
input Count here
</p>
</div>
</div>
<h4>
You have selected {{cart}} items
</h4>
</div>
</div>
</div>
</body>
</html>
CSS
body {
font-family: tahoma;
color:#282828;
margin: 0px;
}
.nav-bar {
background: linear-gradient(-90deg, #84CF6A, #16C0B0);
height: 60px;
margin-bottom: 15px;
}
.product {
display: flex;
flex-flow: wrap;
padding: 1rem;
}
img {
border: 1px solid #d8d8d8;
width: 70%;
margin: 40px;
box-shadow: 0px .5px 1px #d8d8d8;
}
.product-image {
width: 80%;
}
.product-image,
.product-info {
margin-top: 5px;
width: 50%;
}
.color-box {
width: 40px;
height: 40px;
margin-top: 5px;
}
.divcontainer{
display: inline-flex;
}
.cart {
margin-right: 25px;
float: right;
border: 1px solid #d8d8d8;
padding: 5px 20px;
}
button {
margin-top: 30px;
border: none;
background-color: #1E95EA;
color: white;
height: 40px;
width: 100px;
font-size: 14px;
}
.disabledButton {
background-color: #d8d8d8;
}
.review-form {
width: 400px;
padding: 20px;
margin: 40px;
border: 1px solid #d8d8d8;
}
textarea {
width: 100%;
height: 60px;
}
.tab {
margin-left: 20px;
cursor: pointer;
}
.item {
padding-left: 50%;
padding: 0px 0px 0px 16px !important;
border: none;
vertical-align: middle;
height: 48px;
line-height: 48px;
float:left;
}
.direct{
font-size: small;
font-style: oblique;
text-shadow: 0 0 4px black;
}
}
.activeTab {
color: #16C0B0;
text-decoration: underline;
}
Vue
var app =new Vue({
el:'#app',
data:{
product :"Socks",
image :"https://image.shutterstock.com/image-photo/orange-socks-on-isolated-white-260nw-1237524934.jpg",
inStock :true,
details :["some Cotton","Ployester","ABC"],
colors :[{Id:1,name:"Orange",image:"https://image.shutterstock.com/image-photo/orange-socks-on-isolated-white-260nw-1237524934.jpg"},{Id:2,name:"Purple",image:"https://image.shutterstock.com/image-photo/pair-purple-socks-on-isolated-260nw-743175598.jpg"}],
cart :0
},
methods:{ addToCart(){this.cart =Number(this.cart)+1},
updateProduct(image){this.image=image},
}
})