Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3251d861fc | ||
|
|
6253c36939 | ||
|
|
3cfcc7cbdd | ||
|
|
1a8cd4892b | ||
|
|
8c51141d99 | ||
|
|
e5a0b6e460 | ||
|
|
40c519c162 |
@ -1,15 +0,0 @@
|
|||||||
app.component("product-details", {
|
|
||||||
props: {
|
|
||||||
details: [],
|
|
||||||
},
|
|
||||||
template:
|
|
||||||
/*html*/
|
|
||||||
`
|
|
||||||
<div class="product-details">
|
|
||||||
<p>Details:</p>
|
|
||||||
<div v-for="(detail, index) in details">
|
|
||||||
{{ detail }}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
`,
|
|
||||||
});
|
|
||||||
@ -8,33 +8,40 @@ app.component("product-display", {
|
|||||||
template:
|
template:
|
||||||
/*html*/
|
/*html*/
|
||||||
`<div class="product-display">
|
`<div class="product-display">
|
||||||
<div class="product-container">
|
<div class="product-container">
|
||||||
<div class="product-image">
|
<div class="product-image">
|
||||||
<img v-bind:src="image">
|
<img v-bind:src="image">
|
||||||
</div>
|
</div>
|
||||||
<div class="product-info">
|
<div class="product-info">
|
||||||
<h1>{{ title }}</h1>
|
<h1>{{ title }}</h1>
|
||||||
<p v-if="inStock">In Stock</p>
|
|
||||||
<p v-else>Out of Stock</p>
|
<p v-if="inStock">In Stock</p>
|
||||||
<div
|
<p v-else>Out of Stock</p>
|
||||||
v-for="(variant, index) in variants"
|
|
||||||
:key="variant.id"
|
<p>Shipping: {{ shipping }}</p>
|
||||||
@mouseover="updateVariant(index)"
|
|
||||||
class="color-circle"
|
<ul>
|
||||||
:style="{ backgroundColor: variant.color }">
|
<li v-for="detail in details">{{ detail }}</li>
|
||||||
</div>
|
</ul>
|
||||||
<p>Shipping: {{ shipping }}</p>
|
|
||||||
<product-details :details="details"></product-details>
|
<div
|
||||||
<button
|
v-for="(variant, index) in variants"
|
||||||
class="button"
|
:key="variant.id"
|
||||||
:class="{ disabledButton: !inStock }"
|
@mouseover="updateVariant(index)"
|
||||||
:disabled="!inStock"
|
class="color-circle"
|
||||||
v-on:click="addToCart">
|
:style="{ backgroundColor: variant.color }">
|
||||||
Add to Cart
|
</div>
|
||||||
</button>
|
|
||||||
</div>
|
<button
|
||||||
</div>
|
class="button"
|
||||||
</div>`,
|
:class="{ disabledButton: !inStock }"
|
||||||
|
:disabled="!inStock"
|
||||||
|
v-on:click="addToCart">
|
||||||
|
Add to Cart
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>`,
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
product: "Socks",
|
product: "Socks",
|
||||||
@ -59,6 +66,7 @@ app.component("product-display", {
|
|||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
addToCart() {
|
addToCart() {
|
||||||
|
this.$emit("add-to-cart", this.variants[this.selectedVariant].id);
|
||||||
this.cart += 1;
|
this.cart += 1;
|
||||||
},
|
},
|
||||||
updateVariant(index) {
|
updateVariant(index) {
|
||||||
@ -66,13 +74,6 @@ app.component("product-display", {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
shipping() {
|
|
||||||
if (this.premium) {
|
|
||||||
return "Free";
|
|
||||||
} else {
|
|
||||||
return 2.99;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
title() {
|
title() {
|
||||||
return this.brand + " " + this.product;
|
return this.brand + " " + this.product;
|
||||||
},
|
},
|
||||||
@ -80,8 +81,13 @@ app.component("product-display", {
|
|||||||
return this.variants[this.selectedVariant].image;
|
return this.variants[this.selectedVariant].image;
|
||||||
},
|
},
|
||||||
inStock() {
|
inStock() {
|
||||||
return;
|
return this.variants[this.selectedVariant].quantity;
|
||||||
this.variants[this.selectedVariant].quantity;
|
},
|
||||||
|
shipping() {
|
||||||
|
if (this.premium) {
|
||||||
|
return "Free";
|
||||||
|
}
|
||||||
|
return 2.99;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
12
index.html
12
index.html
@ -7,19 +7,23 @@
|
|||||||
<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.11/dist/vue.global.js"></script>
|
||||||
<!-- Import Components -->
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div id="app">
|
<div id="app">
|
||||||
<div class="nav-bar"></div>
|
<div class="nav-bar"></div>
|
||||||
<div class="cart">Cart({{ cart }})</div>
|
|
||||||
<product-display :premium="premium"></product-display>
|
<div class="cart">Cart({{ cart.length }})</div>
|
||||||
|
<product-display
|
||||||
|
:premium="premium"
|
||||||
|
@add-to-cart="updateCart"
|
||||||
|
></product-display>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Import App -->
|
<!-- Import App -->
|
||||||
<script src="./main.js"></script>
|
<script src="./main.js"></script>
|
||||||
|
|
||||||
|
<!-- Import Components -->
|
||||||
<script src="./components/ProductDisplay.js"></script>
|
<script src="./components/ProductDisplay.js"></script>
|
||||||
<script src="./components/ProductDetails.js"></script>
|
|
||||||
|
|
||||||
<!-- Mount App -->
|
<!-- Mount App -->
|
||||||
<script>
|
<script>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user