대댓글 진행중
This commit is contained in:
parent
e81229db4c
commit
7774bfe80a
@ -13,7 +13,7 @@
|
||||
<div class="w-100">
|
||||
<textarea
|
||||
class="form-control"
|
||||
placeholder="주제에 대한 생각을 자유롭게 댓글로 표현해 주세요. 여러분의 다양한 의견을 기다립니다."
|
||||
placeholder="댓글 달기"
|
||||
rows="3"
|
||||
v-model="comment"
|
||||
></textarea>
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
<template>
|
||||
<div>
|
||||
<BoardProfile :profileName="comment.author" :showDetail="false" :author="true" :isChild="isChild" />
|
||||
<BoardProfile :profileName="comment.author" :date="comment.createdAt" :showDetail="false" :author="true" :isChild="isChild" />
|
||||
<div class="mt-6">
|
||||
<p class="m-0">{{ comment.content }}</p>
|
||||
</div>
|
||||
@ -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 배열에 추가
|
||||
};
|
||||
|
||||
|
||||
|
||||
@ -5,7 +5,10 @@
|
||||
:key="comment.id"
|
||||
class="mt-8"
|
||||
>
|
||||
<BoardComment :comment="comment" @submitComment="addComment" />
|
||||
<BoardComment
|
||||
:comment="comment"
|
||||
@submitComment="addComment"
|
||||
/>
|
||||
</li>
|
||||
</ul>
|
||||
</template>
|
||||
|
||||
@ -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(() => {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user