From fbaef5392f6967737371720f37925bf1641c3d4b Mon Sep 17 00:00:00 2001 From: James Collins Date: Wed, 29 Mar 2023 16:43:15 +1000 Subject: [PATCH] test foreach exists --- .../js/components/SMInputAttachments.vue | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/resources/js/components/SMInputAttachments.vue b/resources/js/components/SMInputAttachments.vue index fa3589b..fb10e97 100644 --- a/resources/js/components/SMInputAttachments.vue +++ b/resources/js/components/SMInputAttachments.vue @@ -106,21 +106,23 @@ const handleClickRemove = (media_id: string) => { const handleLoad = () => { mediaItems.value = []; - value.value.forEach((item) => { - api.get({ - url: `/media/${item}`, - }) - .then((result) => { - if (result.data) { - const data = result.data as MediaResponse; - - mediaItems.value.push(data.medium); - } + if (value.value && typeof value.value.forEach === "function") { + value.value.forEach((item) => { + api.get({ + url: `/media/${item}`, }) - .catch(() => { - /* empty */ - }); - }); + .then((result) => { + if (result.data) { + const data = result.data as MediaResponse; + + mediaItems.value.push(data.medium); + } + }) + .catch(() => { + /* empty */ + }); + }); + } }; watch(