Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8d5ddd851e | ||
|
|
0961e591ff | ||
|
|
f6a734f951 |
@ -25,7 +25,7 @@ body {
|
|||||||
margin: 25px 100px;
|
margin: 25px 100px;
|
||||||
float: right;
|
float: right;
|
||||||
border: 1px solid #d8d8d8;
|
border: 1px solid #d8d8d8;
|
||||||
padding: 30px 30px;
|
padding: 10px 30px;
|
||||||
background-color: white;
|
background-color: white;
|
||||||
-webkit-box-shadow: 0px 2px 15px -12px rgba(0, 0, 0, 0.57);
|
-webkit-box-shadow: 0px 2px 15px -12px rgba(0, 0, 0, 0.57);
|
||||||
-moz-box-shadow: 0px 2px 15px -12px rgba(0, 0, 0, 0.57);
|
-moz-box-shadow: 0px 2px 15px -12px rgba(0, 0, 0, 0.57);
|
||||||
@ -89,7 +89,7 @@ li {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.out-of-stock-img {
|
.out-of-stock-img {
|
||||||
opacity: 0.5;
|
opacity:0.5
|
||||||
}
|
}
|
||||||
|
|
||||||
p {
|
p {
|
||||||
|
|||||||
@ -1,93 +0,0 @@
|
|||||||
app.component("product-display", {
|
|
||||||
props: {
|
|
||||||
premium: {
|
|
||||||
type: Boolean,
|
|
||||||
required: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
template:
|
|
||||||
/*html*/
|
|
||||||
`<div class="product-display">
|
|
||||||
<div class="product-container">
|
|
||||||
<div class="product-image">
|
|
||||||
<img v-bind:src="image">
|
|
||||||
</div>
|
|
||||||
<div class="product-info">
|
|
||||||
<h1>{{ title }}</h1>
|
|
||||||
|
|
||||||
<p v-if="inStock">In Stock</p>
|
|
||||||
<p v-else>Out of Stock</p>
|
|
||||||
|
|
||||||
<p>Shipping: {{ shipping }}</p>
|
|
||||||
|
|
||||||
<ul>
|
|
||||||
<li v-for="detail in details">{{ detail }}</li>
|
|
||||||
</ul>
|
|
||||||
|
|
||||||
<div
|
|
||||||
v-for="(variant, index) in variants"
|
|
||||||
:key="variant.id"
|
|
||||||
@mouseover="updateVariant(index)"
|
|
||||||
class="color-circle"
|
|
||||||
:style="{ backgroundColor: variant.color }">
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<button
|
|
||||||
class="button"
|
|
||||||
:class="{ disabledButton: !inStock }"
|
|
||||||
:disabled="!inStock"
|
|
||||||
v-on:click="addToCart">
|
|
||||||
Add to Cart
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>`,
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
product: "Socks",
|
|
||||||
brand: "Vue Mastery",
|
|
||||||
selectedVariant: 0,
|
|
||||||
details: ["50% cotton", "30% wool", "20% polyester"],
|
|
||||||
variants: [
|
|
||||||
{
|
|
||||||
id: 2234,
|
|
||||||
color: "green",
|
|
||||||
image: "./assets/images/socks_green.jpg",
|
|
||||||
quantity: 50,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id: 2235,
|
|
||||||
color: "blue",
|
|
||||||
image: "./assets/images/socks_blue.jpg",
|
|
||||||
quantity: 0,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
addToCart() {
|
|
||||||
this.$emit("add-to-cart", this.variants[this.selectedVariant].id);
|
|
||||||
this.cart += 1;
|
|
||||||
},
|
|
||||||
updateVariant(index) {
|
|
||||||
this.selectedVariant = index;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
computed: {
|
|
||||||
title() {
|
|
||||||
return this.brand + " " + this.product;
|
|
||||||
},
|
|
||||||
image() {
|
|
||||||
return this.variants[this.selectedVariant].image;
|
|
||||||
},
|
|
||||||
inStock() {
|
|
||||||
return this.variants[this.selectedVariant].quantity;
|
|
||||||
},
|
|
||||||
shipping() {
|
|
||||||
if (this.premium) {
|
|
||||||
return "Free";
|
|
||||||
}
|
|
||||||
return 2.99;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
44
index.html
44
index.html
@ -1,33 +1,19 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<title>Vue Mastery</title>
|
<title>Vue Mastery</title>
|
||||||
<!-- Import Styles -->
|
<!-- Import Styles -->
|
||||||
<link rel="stylesheet" href="./assets/styles.css" />
|
<link rel="stylesheet" href="./assets/styles.css" />
|
||||||
<!-- Import Vue.js -->
|
<!-- Import Vue.js -->
|
||||||
<script src="https://unpkg.com/vue@3.0.11/dist/vue.global.js"></script>
|
<script src="https://unpkg.com/vue@3.0.0-beta.12/dist/vue.global.js"></script>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<div class="nav-bar"></div>
|
<h1>Product goes here</h1>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="cart">Cart({{ cart.length }})</div>
|
<!-- Import Js -->
|
||||||
<product-display
|
<script src="./main.js"></script>
|
||||||
:premium="premium"
|
</body>
|
||||||
@add-to-cart="updateCart"
|
|
||||||
></product-display>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<!-- Import App -->
|
|
||||||
<script src="./main.js"></script>
|
|
||||||
|
|
||||||
<!-- Import Components -->
|
|
||||||
<script src="./components/ProductDisplay.js"></script>
|
|
||||||
|
|
||||||
<!-- Mount App -->
|
|
||||||
<script>
|
|
||||||
const mountedApp = app.mount("#app");
|
|
||||||
</script>
|
|
||||||
</body>
|
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user