WIP L10.4
This commit is contained in:
parent
6253c36939
commit
3251d861fc
@ -1,9 +1,9 @@
|
|||||||
app.component('product-display', {
|
app.component("product-display", {
|
||||||
props: {
|
props: {
|
||||||
premium: {
|
premium: {
|
||||||
type: Boolean,
|
type: Boolean,
|
||||||
required: true
|
required: true,
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
template:
|
template:
|
||||||
/*html*/
|
/*html*/
|
||||||
@ -44,39 +44,50 @@ app.component('product-display', {
|
|||||||
</div>`,
|
</div>`,
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
product: 'Socks',
|
product: "Socks",
|
||||||
brand: 'Vue Mastery',
|
brand: "Vue Mastery",
|
||||||
selectedVariant: 0,
|
selectedVariant: 0,
|
||||||
details: ['50% cotton', '30% wool', '20% polyester'],
|
details: ["50% cotton", "30% wool", "20% polyester"],
|
||||||
variants: [
|
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 },
|
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: {
|
methods: {
|
||||||
addToCart() {
|
addToCart() {
|
||||||
this.cart += 1
|
this.$emit("add-to-cart", this.variants[this.selectedVariant].id);
|
||||||
|
this.cart += 1;
|
||||||
},
|
},
|
||||||
updateVariant(index) {
|
updateVariant(index) {
|
||||||
this.selectedVariant = index
|
this.selectedVariant = index;
|
||||||
}
|
},
|
||||||
},
|
},
|
||||||
computed: {
|
computed: {
|
||||||
title() {
|
title() {
|
||||||
return this.brand + ' ' + this.product
|
return this.brand + " " + this.product;
|
||||||
},
|
},
|
||||||
image() {
|
image() {
|
||||||
return this.variants[this.selectedVariant].image
|
return this.variants[this.selectedVariant].image;
|
||||||
},
|
},
|
||||||
inStock() {
|
inStock() {
|
||||||
return this.variants[this.selectedVariant].quantity
|
return this.variants[this.selectedVariant].quantity;
|
||||||
},
|
},
|
||||||
shipping() {
|
shipping() {
|
||||||
if (this.premium) {
|
if (this.premium) {
|
||||||
return 'Free'
|
return "Free";
|
||||||
}
|
}
|
||||||
return 2.99
|
return 2.99;
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
})
|
});
|
||||||
|
|||||||
@ -12,8 +12,11 @@
|
|||||||
<div id="app">
|
<div id="app">
|
||||||
<div class="nav-bar"></div>
|
<div class="nav-bar"></div>
|
||||||
|
|
||||||
<div class="cart">Cart({{ cart }})</div>
|
<div class="cart">Cart({{ cart.length }})</div>
|
||||||
<product-display :premium="premium"></product-display>
|
<product-display
|
||||||
|
:premium="premium"
|
||||||
|
@add-to-cart="updateCart"
|
||||||
|
></product-display>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Import App -->
|
<!-- Import App -->
|
||||||
@ -24,7 +27,7 @@
|
|||||||
|
|
||||||
<!-- Mount App -->
|
<!-- Mount App -->
|
||||||
<script>
|
<script>
|
||||||
const mountedApp = app.mount('#app')
|
const mountedApp = app.mount("#app");
|
||||||
</script>
|
</script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user