From 220f32257cc65e630b3b67a6bfc4c554686d579d Mon Sep 17 00:00:00 2001 From: aminecmi Date: Sun, 17 Jul 2022 22:16:23 +0200 Subject: [PATCH] Deleting items. --- src/components/ListItem.vue | 9 ++++++--- src/views/List.vue | 16 ++++++++++++++-- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/src/components/ListItem.vue b/src/components/ListItem.vue index 0404c87..3612341 100644 --- a/src/components/ListItem.vue +++ b/src/components/ListItem.vue @@ -10,9 +10,9 @@ -
- - Save +
@@ -31,6 +31,9 @@ export default { methods: { updateItem: function () { this.$emit('updateItem', {id: this.element.id, checked: this.element.checked}, true) + }, + deleteElement: function () { + this.$emit('deleteElement', this.element.id) } } } diff --git a/src/views/List.vue b/src/views/List.vue index 7dcf5db..176ebc1 100644 --- a/src/views/List.vue +++ b/src/views/List.vue @@ -31,11 +31,11 @@ @change="onChange" item-key="id" v-if="searchQ.length <= 0">
- +
@@ -100,6 +100,18 @@ export default { item.loading = false; }) }, + deleteElement: function (itemId) { + fetch(`${process.env.VUE_APP_API_BASE_URL}/api/lists/` + this.listId + `/items/` + itemId, { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json;charset=utf-8', + 'X-API-KEY': localStorage.getItem('KEY') + } + }).finally(() => { + this.initialItems = this.initialItems.filter(i => i.id !== itemId) + this.recopyItemsObject(); + }) + }, recopyItemsObject: function () { this.searchResults = this.initialItems.map(x => ({...x})); },