app.component('product-display', { props: { brand:{ type: String, required: true } }, template: `

{{ title }}

Only {{ inStock }} left!

In Stock

Out of Stock

  • {{detail}}
{{ size.size }}
`, data() { return { product: 'Socks', selectedVariant: 0, inventory: 11, details: ['50% cotton', '30% wool', '20% polyester'], variants: [ {id: 1, color: 'green', image: './assets/images/socks_green.jpg', quantity: 11, ordered: 0}, {id: 2, color: 'blue', image: './assets/images/socks_blue.jpg', quantity: 0, ordered: 0}, ], sizes: [ {id: 3, size: 'small'}, {id: 4, size: 'large'}, ] } }, methods: { addToCart() { this.variants[this.selectedVariant].ordered += 1 this.variants[this.selectedVariant].quantity -= 1 this.$emit('add-to-cart', this.titleLong) }, removeFromCart() { this.variants[this.selectedVariant].ordered -= 1 this.variants[this.selectedVariant].quantity += 1 this.$emit('remove-from-cart', this.titleLong) }, updateVariant(index) { this.selectedVariant = index }, }, computed: { title() { return this.brand + ' ' + this.product }, titleLong() { return this.brand + '-' + this.product + '-' + this.variants[this.selectedVariant].id }, image() { return this.variants[this.selectedVariant].image }, cartContains() { return (this.variants[this.selectedVariant].ordered > 0) }, inStock() { return this.variants[this.selectedVariant].quantity }, } })