Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bb65d2a275 | ||
|
|
f91df3ac12 | ||
|
|
0a13d4e607 | ||
|
|
1572b8c23e | ||
|
|
12062da9d1 |
@ -88,10 +88,6 @@ li {
|
|||||||
box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.57);
|
box-shadow: 1px 1px 5px rgba(0, 0, 0, 0.57);
|
||||||
}
|
}
|
||||||
|
|
||||||
.out-of-stock-img {
|
|
||||||
opacity: 0.5;
|
|
||||||
}
|
|
||||||
|
|
||||||
p {
|
p {
|
||||||
font-size: 22px;
|
font-size: 22px;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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;
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
39
index.html
39
index.html
@ -12,19 +12,42 @@
|
|||||||
<div id="app">
|
<div id="app">
|
||||||
<div class="nav-bar"></div>
|
<div class="nav-bar"></div>
|
||||||
|
|
||||||
<div class="cart">Cart({{ cart.length }})</div>
|
<div class="cart">Cart({{ cart }})</div>
|
||||||
<product-display
|
|
||||||
:premium="premium"
|
<div class="product-display">
|
||||||
@add-to-cart="updateCart"
|
<div class="product-container">
|
||||||
></product-display>
|
<div class="product-image">
|
||||||
|
<img v-bind:src="image" />
|
||||||
|
</div>
|
||||||
|
<div class="product-info">
|
||||||
|
<h1>{{ product }}</h1>
|
||||||
|
<p v-if="inStock">In Stock</p>
|
||||||
|
<p v-else>Out of Stock</p>
|
||||||
|
<ul>
|
||||||
|
<li v-for="detail in details">{{ detail }}</li>
|
||||||
|
</ul>
|
||||||
|
<div
|
||||||
|
@mouseover="this.image = variant.image"
|
||||||
|
v-for="variant in variants"
|
||||||
|
:key="variant.id"
|
||||||
|
>
|
||||||
|
{{ variant.color }}
|
||||||
|
</div>
|
||||||
|
<button class="button" @click="cart++">
|
||||||
|
Add to Cart
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button class="button" @click="cart--" v-if="cart > 0">
|
||||||
|
Remove item
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Import App -->
|
<!-- Import App -->
|
||||||
<script src="./main.js"></script>
|
<script src="./main.js"></script>
|
||||||
|
|
||||||
<!-- Import Components -->
|
|
||||||
<script src="./components/ProductDisplay.js"></script>
|
|
||||||
|
|
||||||
<!-- Mount App -->
|
<!-- Mount App -->
|
||||||
<script>
|
<script>
|
||||||
const mountedApp = app.mount("#app");
|
const mountedApp = app.mount("#app");
|
||||||
|
|||||||
26
main.js
26
main.js
@ -1,13 +1,15 @@
|
|||||||
const app = Vue.createApp({
|
const app = Vue.createApp({
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
cart: [],
|
cart:0,
|
||||||
premium: true,
|
product: 'Socks',
|
||||||
};
|
image: './assets/images/socks_blue.jpg',
|
||||||
},
|
inStock: true,
|
||||||
methods: {
|
details: ['50% cotton', '30% wool', '20% polyester'],
|
||||||
updateCart(id) {
|
variants: [
|
||||||
this.cart.push(id);
|
{ id: 2234, color: 'green', image: './assets/images/socks_green.jpg' },
|
||||||
},
|
{ id: 2235, color: 'blue', image: './assets/images/socks_blue.jpg' },
|
||||||
},
|
]
|
||||||
});
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user