From e81229db4ce0d1ee058595c75119e942560c1706 Mon Sep 17 00:00:00 2001 From: kimdaae328 Date: Thu, 13 Feb 2025 12:03:43 +0900 Subject: [PATCH] =?UTF-8?q?=EB=8C=93=EA=B8=80=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EB=B0=8F=20=EB=93=B1=EB=A1=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/board/BoardComment.vue | 3 +- src/components/board/BoardCommentList.vue | 39 ++++---------------- src/views/board/BoardView.vue | 44 +++++++++++++++++------ 3 files changed, 40 insertions(+), 46 deletions(-) diff --git a/src/components/board/BoardComment.vue b/src/components/board/BoardComment.vue index 7ebe4a5..d2a92fd 100644 --- a/src/components/board/BoardComment.vue +++ b/src/components/board/BoardComment.vue @@ -35,8 +35,7 @@ import BoardProfile from './BoardProfile.vue'; import BoardComentArea from './BoardComentArea.vue'; import PlusButton from '../button/PlusBtn.vue'; -import { ref } from 'vue'; -import { defineEmits } from 'vue'; +import { defineProps, defineEmits, ref } from 'vue'; const props = defineProps({ comment: { diff --git a/src/components/board/BoardCommentList.vue b/src/components/board/BoardCommentList.vue index f1c7116..d122fc3 100644 --- a/src/components/board/BoardCommentList.vue +++ b/src/components/board/BoardCommentList.vue @@ -11,11 +11,15 @@ diff --git a/src/views/board/BoardView.vue b/src/views/board/BoardView.vue index 3e1e243..2304993 100644 --- a/src/views/board/BoardView.vue +++ b/src/views/board/BoardView.vue @@ -68,6 +68,7 @@ + @@ -104,6 +105,7 @@ const likeClicked = ref(false); const dislikeClicked = ref(false); const commentNum = ref(0); const attachment = ref(false); +const comments = ref([]); const route = useRoute(); const currentBoardId = ref(Number(route.params.id)); @@ -206,17 +208,36 @@ const handleCommentSubmit = async ({ comment, password }) => { }; // 댓글 목록 조회 -// const fetchComments = async () => { -// try { -// const response = await axios.get(`board/${currentBoardId.value}/comments`); -// if (response.status === 200) { -// comments.value = response.data.data || []; -// console.log('📋 댓글 목록:', comments.value); -// } -// } catch (error) { -// console.error('댓글 목록 불러오기 오류:', error); -// } -// }; +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); + + comments.value = response.data.data.map(comment => ({ + id: comment.LOCCMTSEQ, // 고유 ID + // author: comment.LOCCMTWRITER || "익명 사용자", // 작성자 + content: comment.LOCCMTRPY, // 댓글 내용 + createdAt: comment.LOCCMTUDT, // 생성 날짜 + children: comment.children ? comment.children.map(child => ({ + id: child.LOCCMTSEQ, + // author: child.LOCCMTWRITER || "익명 사용자", + content: child.LOCCMTRPY, + createdAt: child.LOCCMTUDT, + })) : [] + })); + + // comments.value.sort((a, b) => b.createdAt - a.createdAt); + + console.log("📌 변환된 comments 데이터:", comments.value); + + } catch (error) { + console.error('❌ 댓글 목록 불러오기 오류:', error); + } +}; // 날짜 @@ -228,5 +249,6 @@ const formattedBoardDate = computed(() => { // 컴포넌트 마운트 시 데이터 로드 onMounted(() => { fetchBoardDetails() + fetchComments() });