Feat: Add comment list

This commit is contained in:
이정혁 2024-05-14 17:37:36 +09:00
parent 034e4b1126
commit b84c96ad01
3 changed files with 67 additions and 1 deletions

22
src/api/comment.js Normal file
View File

@ -0,0 +1,22 @@
import { localAxios } from '@/utils/http-commons';
const local = localAxios;
function getComment(articleId, success, fail) {
//list
local.get(`/comment/${articleId}`).then(success).catch(fail);
}
function addComment(comment, success, fail) {
local.post('/comment', JSON.stringify(comment)).then(success).catch(fail);
}
function updateComment(text, id, success, fail) {
local.put(`/comment/${id}`, text).then(success).catch(fail);
}
function deleteComment(id, success, fail) {
local.delete(`/comment/${id}`).then(success).catch(fail);
}
export { getComment, addComment, updateComment, deleteComment };

View File

@ -3,10 +3,11 @@ import { ref } from 'vue';
import { useRoute } from 'vue-router';
import BoardHeader from './BoardHeader.vue';
import { getArticle } from '@/api/article';
import CommentList from '@/components/article/CommentList.vue';
const route = useRoute();
const id = route.params.id;
const id = Number(route.params.id);
const article = ref({});
// function mockAPI() {
@ -42,6 +43,8 @@ getArticle(id, ({ data }) => {
</template>
</BoardHeader>
<p>{{ article.text }}</p>
<CommentList :id="id"></CommentList>
</template>
<style scoped>

View File

@ -0,0 +1,41 @@
<script setup>
import { ref } from 'vue';
import { getComment } from '@/api/comment';
const props = defineProps({ id: Number });
const id = props.id;
const comments = ref([]);
const text = ref('');
getComment(id, ({ data }) => {
comments.value = data;
});
</script>
<template>
<div>
<h2>댓글</h2>
<input type="text" ref="textDiv" v-model="text" />
</div>
<ul>
<li v-for="comment in comments" :key="comment.id">
<div class="info">
<div class="nickname">{{ comment.nickname }}</div>
<div class="date">{{ comment.date }}</div>
</div>
<div class="info">
<div class="text">{{ comment.text }}</div>
</div>
</li>
</ul>
</template>
<style scoped>
.info {
display: flex;
gap: 20px;
font-size: 0.8rem;
color: var(--color-text-secondary);
}
</style>