Compare commits

..

3 Commits

Author SHA1 Message Date
bwbl
7555f030e0 L9 2026-01-13 16:02:16 +01:00
Andy
bc68ec8034 update 2022-05-30 15:18:36 -04:00
Andy
82171f66ab update cdn link 2021-04-09 15:57:11 -04:00
4 changed files with 57 additions and 56 deletions

View File

@ -0,0 +1,15 @@
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>
`,
});

View File

@ -14,16 +14,8 @@ app.component("product-display", {
</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"
@ -31,7 +23,8 @@ app.component("product-display", {
class="color-circle"
:style="{ backgroundColor: variant.color }">
</div>
<p>Shipping: {{ shipping }}</p>
<product-details :details="details"></product-details>
<button
class="button"
:class="{ disabledButton: !inStock }"
@ -66,7 +59,6 @@ app.component("product-display", {
},
methods: {
addToCart() {
this.$emit("add-to-cart", this.variants[this.selectedVariant].id);
this.cart += 1;
},
updateVariant(index) {
@ -74,6 +66,13 @@ app.component("product-display", {
},
},
computed: {
shipping() {
if (this.premium) {
return "Free";
} else {
return 2.99;
}
},
title() {
return this.brand + " " + this.product;
},
@ -81,13 +80,8 @@ app.component("product-display", {
return this.variants[this.selectedVariant].image;
},
inStock() {
return this.variants[this.selectedVariant].quantity;
},
shipping() {
if (this.premium) {
return "Free";
}
return 2.99;
return;
this.variants[this.selectedVariant].quantity;
},
},
});

View File

@ -7,23 +7,19 @@
<link rel="stylesheet" href="./assets/styles.css" />
<!-- Import Vue.js -->
<script src="https://unpkg.com/vue@3.0.11/dist/vue.global.js"></script>
<!-- Import Components -->
</head>
<body>
<div id="app">
<div class="nav-bar"></div>
<div class="cart">Cart({{ cart.length }})</div>
<product-display
:premium="premium"
@add-to-cart="updateCart"
></product-display>
<div class="cart">Cart({{ cart }})</div>
<product-display :premium="premium"></product-display>
</div>
<!-- Import App -->
<script src="./main.js"></script>
<!-- Import Components -->
<script src="./components/ProductDisplay.js"></script>
<script src="./components/ProductDetails.js"></script>
<!-- Mount App -->
<script>

View File

@ -1,13 +1,9 @@
const app = Vue.createApp({
data() {
return {
cart: [],
cart: 0,
premium: true,
};
},
methods: {
updateCart(id) {
this.cart.push(id);
},
},
methods: {},
});