From deb62dd10cfeae1087b10dab96602980e85d71d2 Mon Sep 17 00:00:00 2001 From: Kostya Date: Tue, 30 Jan 2024 14:21:02 +0300 Subject: [PATCH] added if block for check response type --- luckydiamond/src/components/ChatComponent.vue | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/luckydiamond/src/components/ChatComponent.vue b/luckydiamond/src/components/ChatComponent.vue index c0ebe58..9ad4b69 100644 --- a/luckydiamond/src/components/ChatComponent.vue +++ b/luckydiamond/src/components/ChatComponent.vue @@ -91,19 +91,21 @@ export default { }, created() { GetChatHistory().then((response) => { - response.forEach((element) => { - let imageUrl = "https://avatar.spworlds.ru/face/55/" + element.userName; + if (response && response.length) { + response.forEach((element) => { + let imageUrl = "https://avatar.spworlds.ru/face/55/" + element.userName; - const MsgUser = { - id: this.id + 1, - msg: element.message, - username: element.userName, - icon: imageUrl, - }; + const MsgUser = { + id: this.id + 1, + msg: element.message, + username: element.userName, + icon: imageUrl, + }; - this.array.push(MsgUser); - }); - this.ScrollToBottom(); + this.array.push(MsgUser); + }); + this.ScrollToBottom(); + } }); }, };