댓글 조회 및 등록

This commit is contained in:
kimdaae328 2025-02-13 12:03:43 +09:00
parent 34a1c8360d
commit e81229db4c
3 changed files with 40 additions and 46 deletions

View File

@ -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: {

View File

@ -11,11 +11,15 @@
</template>
<script setup>
import { ref, defineProps, defineEmits } from 'vue';
import { defineProps, defineEmits } from 'vue';
import BoardComment from './BoardComment.vue'
const props = defineProps({
comments: Array
comments: {
type: Array,
required: true,
default: () => []
}
});
const emit = defineEmits(['reply']);
@ -24,35 +28,4 @@ const addComment = (replyData) => {
emit('reply', replyData);
};
// const comments = ref([
// {
// id: 1,
// author: '',
// content: ' .',
// children: [
// {
// id: 2,
// author: '1',
// content: '!',
// },
// {
// id: 3,
// author: '2',
// content: '..',
// },
// ],
// },
// {
// id: 4,
// author: '4',
// content: ' .',
// children: [],
// },
// {
// id: 5,
// author: '5',
// content: '',
// children: [],
// },
// ]);
</script>

View File

@ -68,6 +68,7 @@
<!-- 댓글 입력 영역 -->
<BoardComentArea :profileName="profileName" :unknown="unknown" @submit="handleCommentSubmit"/>
<!-- <BoardComentArea :profileName="profileName" :unknown="unknown" /> -->
</div>
<!-- 댓글 목록 -->
@ -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()
});
</script>