Skip to content

Commit

Permalink
idk why it wont work
Browse files Browse the repository at this point in the history
  • Loading branch information
JessL868 committed Feb 12, 2025
1 parent 06155dd commit 6f7cd90
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions app/src/cart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { reactive } from 'vue';

export const store = reactive({
cart: []
});
3 changes: 2 additions & 1 deletion app/src/components/GroceryCart.vue
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
<template>
<div>
<h1>Cart</h1>
<h2 v-for="(item, index) in store.cart" :key="index" :index="index">{{ item.name }} - {{ item.cost }}</h2>
</div>
</template>

<script setup>
cart = [];
import { store } from '../cart.js'
</script>

<style scoped>
Expand Down
10 changes: 8 additions & 2 deletions app/src/components/ShopProduce.vue
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
<template>
<div>
<div class="container">
<ProductCss @click="console.log(product)" v-for="product in products" :key="product.name" :product = "product">Add to Cart</ProductCss>
<ProductCss @click="addToCart(product)" v-for="product in products" :key="product.name" :product = "product">Add to Cart</ProductCss>
</div>
</div>
</template>

<script setup>
import cart from '../components/GroceryCart.vue'
import { store } from '../cart.js'
import ProductCss from '../components/ProductCss.vue'
import cart from '../components/GroceryCart.vue'
const products = [
{name: "Broccoli (per lb)",
cost: "$2.99"},
Expand Down Expand Up @@ -51,6 +52,11 @@ const products = [
{name: "Honeydew Melon (per lb)",
cost: "$8.50"}
]
const addToCart = (product) => {
store.cart.push(product);
};
</script>

<style scoped>
Expand Down

0 comments on commit 6f7cd90

Please sign in to comment.