From 7774bfe80a30a7375434d82e0203aa8741d09740 Mon Sep 17 00:00:00 2001 From: kimdaae328 Date: Thu, 13 Feb 2025 13:20:11 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8C=80=EB=8C=93=EA=B8=80=20=EC=A7=84?= =?UTF-8?q?=ED=96=89=EC=A4=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/board/BoardComentArea.vue | 2 +- src/components/board/BoardComment.vue | 10 +++++--- src/components/board/BoardCommentList.vue | 5 +++- src/views/board/BoardView.vue | 30 +++++++++++------------ 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/src/components/board/BoardComentArea.vue b/src/components/board/BoardComentArea.vue index b437a87..84bd0c3 100644 --- a/src/components/board/BoardComentArea.vue +++ b/src/components/board/BoardComentArea.vue @@ -13,7 +13,7 @@
diff --git a/src/components/board/BoardComment.vue b/src/components/board/BoardComment.vue index d2a92fd..2883a12 100644 --- a/src/components/board/BoardComment.vue +++ b/src/components/board/BoardComment.vue @@ -1,6 +1,6 @@ diff --git a/src/views/board/BoardView.vue b/src/views/board/BoardView.vue index 2304993..bf59370 100644 --- a/src/views/board/BoardView.vue +++ b/src/views/board/BoardView.vue @@ -193,12 +193,12 @@ const handleCommentSubmit = async ({ comment, password }) => { LOCCMTPWD: password || null, LOCCMTPNT: 1 }); - console.log('📥 서버 응답 전체:', response.data); + // console.log('📥 서버 응답 전체:', response.data); if (response.status === 200) { console.log('댓글 작성 성공:', response.data.message); - // await fetchComments(); // 댓글 작성 후 목록 갱신 + await fetchComments(); } else { console.error('댓글 작성 실패:', response.data.message); } @@ -209,28 +209,26 @@ const handleCommentSubmit = async ({ comment, password }) => { // 댓글 목록 조회 const fetchComments = async () => { - console.log("🚀 fetchComments() 실행됨"); // ✅ 함수 실행 여부 확인 - try { const response = await axios.get(`board/${currentBoardId.value}/comments`, { params: { LOCBRDSEQ: currentBoardId.value } }); - console.log("📥 API 응답 데이터:", response.data); - + // console.log("📥 API 응답 데이터:", response.data); + comments.value = response.data.data.map(comment => ({ id: comment.LOCCMTSEQ, // 고유 ID - // author: comment.LOCCMTWRITER || "익명 사용자", // 작성자 + author: comment.MEMBERSEQ || "익명 사용자", // 작성자 content: comment.LOCCMTRPY, // 댓글 내용 - createdAt: comment.LOCCMTUDT, // 생성 날짜 + createdAt: formattedDate(comment.LOCCMTRDT), // 생성 날짜 children: comment.children ? comment.children.map(child => ({ id: child.LOCCMTSEQ, - // author: child.LOCCMTWRITER || "익명 사용자", + author: child.MEMBERSEQ || "익명 사용자", content: child.LOCCMTRPY, - createdAt: child.LOCCMTUDT, + createdAt: formattedDate(child.LOCCMTRDT), })) : [] })); - // comments.value.sort((a, b) => b.createdAt - a.createdAt); + comments.value.sort((a, b) => b.id - a.id); console.log("📌 변환된 comments 데이터:", comments.value); @@ -239,12 +237,14 @@ const fetchComments = async () => { } }; - // 날짜 -const formattedBoardDate = computed(() => { - const dateObj = new Date(date.value); +const formattedDate = (dateString) => { + if (!dateString) return "날짜 없음"; + const dateObj = new Date(dateString); return `${dateObj.getFullYear()}-${String(dateObj.getMonth() + 1).padStart(2, '0')}-${String(dateObj.getDate()).padStart(2, '0')} ${String(dateObj.getHours()).padStart(2, '0')}:${String(dateObj.getMinutes()).padStart(2, '0')}`; -}); +}; + +const formattedBoardDate = computed(() => formattedDate(date.value)); // 컴포넌트 마운트 시 데이터 로드 onMounted(() => {