From 42a82a2b314210b30bb55c28a41b7414cc301258 Mon Sep 17 00:00:00 2001 From: adb-sh Date: Sun, 8 Jan 2023 17:31:58 +0100 Subject: [PATCH] add edit items --- src/components/EditItemForm.vue | 51 +++++++++++++++++++++++++++++++++ src/components/ItemList.vue | 6 +++- src/router/index.ts | 6 ++++ src/store/dummyData.ts | 3 ++ src/store/shoppingList.ts | 1 + src/views/EditItem.vue | 24 ++++++++++++++++ 6 files changed, 90 insertions(+), 1 deletion(-) create mode 100644 src/components/EditItemForm.vue create mode 100644 src/views/EditItem.vue diff --git a/src/components/EditItemForm.vue b/src/components/EditItemForm.vue new file mode 100644 index 0000000..a8cc74d --- /dev/null +++ b/src/components/EditItemForm.vue @@ -0,0 +1,51 @@ + + + diff --git a/src/components/ItemList.vue b/src/components/ItemList.vue index 81b68c3..88e36c1 100644 --- a/src/components/ItemList.vue +++ b/src/components/ItemList.vue @@ -12,9 +12,13 @@ defineProps({
{{ user }}
- + {{ item.name }} {{ item.price / 100 }} € +
diff --git a/src/router/index.ts b/src/router/index.ts index 6728da9..322c416 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -2,6 +2,7 @@ import { createRouter, createWebHistory, RouteRecordRaw } from 'vue-router'; import HomeView from '../views/HomeView.vue'; import ShoppingList from '../views/ShoppingList.vue'; import AddItem from '../views/AddItem.vue'; +import EditItem from '../views/EditItem.vue'; const routes: Array = [ { @@ -19,6 +20,11 @@ const routes: Array = [ name: "add-item", component: AddItem, }, + { + path: "/edit-item/:id", + name: "edit-item", + component: EditItem, + }, ]; const router = createRouter({ diff --git a/src/store/dummyData.ts b/src/store/dummyData.ts index daf0013..5c1f687 100644 --- a/src/store/dummyData.ts +++ b/src/store/dummyData.ts @@ -14,17 +14,20 @@ export const dummyList = [ price: 200, user: lukas, isBought: false, + id: 0, }, { name: 'Apple', price: 150, user: lukas, isBought: false, + id: 1, }, { name: 'Butter', price: 149, user: laura, isBought: false, + id: 2, }, ]; diff --git a/src/store/shoppingList.ts b/src/store/shoppingList.ts index af0a168..21eef3d 100644 --- a/src/store/shoppingList.ts +++ b/src/store/shoppingList.ts @@ -10,6 +10,7 @@ type ShoppingItem = { price: number; isBought: boolean; user: User; + id: number; }; export const useShoppingListStore = defineStore('shoppingList', { diff --git a/src/views/EditItem.vue b/src/views/EditItem.vue new file mode 100644 index 0000000..0b3381d --- /dev/null +++ b/src/views/EditItem.vue @@ -0,0 +1,24 @@ + + +