-
+
@@ -62,8 +62,12 @@ const toggleComment = () => {
};
// 부모 컴포넌트에 대댓글 추가 요청
-const addChildComment = (parentId, newComment) => {
- emit('submitComment', parentId, newComment);
+const addChildComment = (newComment) => {
+ console.log("➕ 대댓글 추가됨:", newComment);
+ if (!props.comment.children) {
+ props.comment.children = []; // ✅ 대댓글 배열이 없으면 생성
+ }
+ props.comment.children.push(newComment); // ✅ 부모 댓글의 children 배열에 추가
};
diff --git a/src/components/board/BoardCommentList.vue b/src/components/board/BoardCommentList.vue
index d122fc3..d948fe6 100644
--- a/src/components/board/BoardCommentList.vue
+++ b/src/components/board/BoardCommentList.vue
@@ -5,7 +5,10 @@
:key="comment.id"
class="mt-8"
>
-
+
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(() => {