Compare commits
20 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3251d861fc | ||
|
|
6253c36939 | ||
|
|
3cfcc7cbdd | ||
|
|
1a8cd4892b | ||
|
|
8c51141d99 | ||
|
|
e5a0b6e460 | ||
|
|
40c519c162 | ||
|
|
ac72852668 | ||
|
|
d440ca92fb | ||
|
|
58e74974e0 | ||
|
|
44d8427b7a | ||
|
|
33ef706431 | ||
|
|
7f52372b6c | ||
|
|
2bd501d071 | ||
|
|
a6209b82c8 | ||
|
|
9ce75d24c2 | ||
|
|
a903dd19cb | ||
|
|
2846669a3f | ||
|
|
b92a6c065c | ||
|
|
0f08a0ddb3 |
@ -25,7 +25,7 @@ body {
|
|||||||
margin: 25px 100px;
|
margin: 25px 100px;
|
||||||
float: right;
|
float: right;
|
||||||
border: 1px solid #d8d8d8;
|
border: 1px solid #d8d8d8;
|
||||||
padding: 10px 30px;
|
padding: 30px 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);
|
||||||
|
|||||||
93
components/ProductDisplay.js
Normal file
93
components/ProductDisplay.js
Normal file
@ -0,0 +1,93 @@
|
|||||||
|
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;
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
21
index.html
21
index.html
@ -12,25 +12,22 @@
|
|||||||
<div id="app">
|
<div id="app">
|
||||||
<div class="nav-bar"></div>
|
<div class="nav-bar"></div>
|
||||||
|
|
||||||
<div class="product-display">
|
<div class="cart">Cart({{ cart.length }})</div>
|
||||||
<div class="product-container">
|
<product-display
|
||||||
<div class="product-image">
|
:premium="premium"
|
||||||
<img :src="image" alt="">
|
@add-to-cart="updateCart"
|
||||||
</div>
|
></product-display>
|
||||||
<div class="product-info">
|
|
||||||
<h1>{{ product }}</h1>
|
|
||||||
<a :href="url">{{ url }}</a>
|
|
||||||
</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");
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
16
main.js
16
main.js
@ -1,9 +1,13 @@
|
|||||||
const app = Vue.createApp({
|
const app = Vue.createApp({
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
product: 'Socks',
|
cart: [],
|
||||||
image: './assets/images/socks_green.jpg',
|
premium: true,
|
||||||
url: 'https://etml.ch'
|
};
|
||||||
}
|
},
|
||||||
}
|
methods: {
|
||||||
})
|
updateCart(id) {
|
||||||
|
this.cart.push(id);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user