From 40c519c1624e7519eecefceba78b51f290e4094c Mon Sep 17 00:00:00 2001 From: Adam Jahr Date: Wed, 8 Jul 2020 22:59:10 -0400 Subject: [PATCH] L10 ending code --- components/ProductDisplay.js | 76 ++++++++++++++++++++++++++++++++++++ index.html | 33 +++------------- main.js | 29 ++------------ 3 files changed, 85 insertions(+), 53 deletions(-) create mode 100644 components/ProductDisplay.js diff --git a/components/ProductDisplay.js b/components/ProductDisplay.js new file mode 100644 index 0000000..2e6f72c --- /dev/null +++ b/components/ProductDisplay.js @@ -0,0 +1,76 @@ +app.component('product-display', { + + template: + /*html*/ + `
+
+
+ +
+
+

{{ title }}

+ +

In Stock

+

Out of Stock

+ +

Shipping: {{ shipping }}

+
    +
  • {{ detail }}
  • +
+ +
+
+ + +
+
+
`, + 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) + }, + 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 + } + } +}) \ No newline at end of file diff --git a/index.html b/index.html index 6c61f3b..535269a 100644 --- a/index.html +++ b/index.html @@ -12,39 +12,16 @@
-
Cart({{ cart }})
- -
-
-
- -
-
-

{{ title }}

- -

In Stock

-

Out of Stock

-
    -
  • {{ detail }}
  • -
- -
-
- - -
-
-
+
Cart({{ cart.length }})
+
+ + +