From a4f454d57771a1cc99dcc2aac323891184e0ffb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mar=C3=ADa?= Date: Wed, 20 Aug 2025 14:42:36 +0200 Subject: [PATCH] delete product functionality --- pages/editar/productos/index.vue | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/pages/editar/productos/index.vue b/pages/editar/productos/index.vue index 9b97fb4..1c221fa 100644 --- a/pages/editar/productos/index.vue +++ b/pages/editar/productos/index.vue @@ -15,10 +15,10 @@ - -
@@ -160,9 +160,27 @@ export default { async deleteItem(item) { if (confirm('Confirma que quieres eliminar este producto')) { - await this.$api.delete(`/my_products/${item.item.id}`) - const index = this.products.indexOf(item.item) - this.products.splice(index, 1) + const config = useRuntimeConfig() + try { + await $fetch(`/my_products/${item.item.id}`, { + baseURL: config.public.baseURL, + method: 'DELETE', + headers: { + Authorization: `Bearer ${this.auth.access}`, + }, + }) + const index = this.products.indexOf(item.item) + this.products.splice(index, 1) + this.selectedItemsIndexes = [] + this.modalText = 'Los productos han sido eliminados correctamente.' + this.modalColor = 'success' + this.activeModal = true + } catch (error) { + console.error(error) + this.modalText = 'Ha habido un error' + this.modalColor = 'danger' + this.activeModal = true + } } },