Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/App.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script setup>
import { ref } from 'vue'
import socksGreenImage from './assets/images/socks_green.jpeg'
import socksBlueImage from './assets/images/socks_blue.jpeg'

const product = ref('Socks')
const image = ref(socksGreenImage)
Expand All @@ -9,11 +10,17 @@ const inStock = true
const details = ref(['50% cotton', '30% wool', '20% polyester'])

const variants = ref([
{ id: 2234, color: 'green' },
{ id: 2235, color: 'blue' },
{ id: 2234, color: 'green', image: socksGreenImage },
{ id: 2235, color: 'blue', image: socksBlueImage }
])

const cart = ref(0)
const addToCart = () => cart.value += 1
const removeFromCart = () => cart.value -= 1

const updateImage = (variantImage) => {
image.value = variantImage
}
</script>

<template>
Expand All @@ -34,10 +41,12 @@ const cart = ref(0)
<div
v-for="variant in variants"
:key="variant.id"
@mouseover="updateImage(variant.image)"
>
{{ variant.color }}
</div>
<button class="button">Add to Cart</button>
<button class="button" @:click="addToCart">Add to Cart</button>
<button class="button" @:click="removeFromCart">Remove from Cart</button>
</div>
</div>
</div>
Expand Down