fix,refac: 회의실에서 줄 바꿈이 표기 안되는 버그 수정

This commit is contained in:
2022-07-12 00:09:58 +09:00
parent 48fe26e4b1
commit 87e063e03e
3 changed files with 94 additions and 118 deletions
+24 -45
View File
@@ -32,7 +32,7 @@
</div> </div>
<div id="board"> <div id="board">
<template v-if="articles && articles.length"> <template v-if="articles && articles.length">
<board-article <BoardArticle
v-for="article in articles" v-for="article in articles"
:key="article.no" :key="article.no"
:article="article" :article="article"
@@ -46,8 +46,8 @@
</div> </div>
</template> </template>
<script lang="ts"> <script setup lang="ts">
import { defineComponent, onMounted, reactive, ref } from "vue"; import { onMounted, reactive, ref } from "vue";
import TopBackBar from "@/components/TopBackBar.vue"; import TopBackBar from "@/components/TopBackBar.vue";
import BottomBar from "@/components/BottomBar.vue"; import BottomBar from "@/components/BottomBar.vue";
import BoardArticle from "@/components/BoardArticle.vue"; import BoardArticle from "@/components/BoardArticle.vue";
@@ -55,7 +55,6 @@ import { convertFormData } from "@util/convertFormData";
import axios from "axios"; import axios from "axios";
import type { InvalidResponse } from "@/defs"; import type { InvalidResponse } from "@/defs";
import { autoResizeTextarea } from "@util/autoResizeTextarea"; import { autoResizeTextarea } from "@util/autoResizeTextarea";
import { unwrap } from "@util/unwrap";
export type BoardResponse = { export type BoardResponse = {
result: true; result: true;
articles: Record<number, BoardArticleItem>; articles: Record<number, BoardArticleItem>;
@@ -85,25 +84,17 @@ export type BoardCommentItem = {
text: string; text: string;
}; };
export default defineComponent({ const props = defineProps({
name: "PageBoard",
components: {
TopBackBar,
BottomBar,
BoardArticle,
},
props: {
isSecretBoard: { isSecretBoard: {
type: Boolean, type: Boolean,
required: true, required: true,
}, },
}, });
setup(props) { const newArticleTextForm = ref<HTMLInputElement>();
const newArticleTextForm = ref<HTMLInputElement>(); const articles = reactive<BoardArticleItem[]>([]);
const articles = reactive<BoardArticleItem[]>([]);
const reloadArticles = async () => { const reloadArticles = async () => {
let boardResponse: BoardResponse; let boardResponse: BoardResponse;
try { try {
@@ -129,31 +120,20 @@ export default defineComponent({
articles.length = 0; articles.length = 0;
articles.push(...Object.values(boardResponse.articles)); articles.push(...Object.values(boardResponse.articles));
articles.reverse(); articles.reverse();
}; };
onMounted(async () => { onMounted(async () => {
await reloadArticles(); await reloadArticles();
}); });
return { const title = ref(props.isSecretBoard ? "기밀실" : "회의실");
newArticleTextForm, const newArticle = ref({
articles,
reloadArticles,
};
},
data() {
return {
title: this.isSecretBoard ? "기밀실" : "회의실",
newArticle: {
title: "", title: "",
text: "", text: "",
}, });
};
}, async function submitArticle() {
methods: { const { title, text } = newArticle.value;
autoResizeTextarea,
async submitArticle() {
const { title, text } = this.newArticle;
if (!title && !text) { if (!title && !text) {
return; return;
} }
@@ -166,7 +146,7 @@ export default defineComponent({
method: "post", method: "post",
responseType: "json", responseType: "json",
data: convertFormData({ data: convertFormData({
isSecret: this.isSecretBoard, isSecret: props.isSecretBoard,
title, title,
text, text,
}), }),
@@ -181,12 +161,11 @@ export default defineComponent({
return; return;
} }
this.newArticle = { title: "", text: "" }; newArticle.value = { title: "", text: "" };
const newArticleTextForm = unwrap(this.newArticleTextForm); if (newArticleTextForm.value !== undefined) {
newArticleTextForm.style.height = "auto"; newArticleTextForm.value.style.height = "auto";
}
await this.reloadArticles(); await reloadArticles();
}, }
},
});
</script> </script>
+3 -3
View File
@@ -20,7 +20,7 @@
</div> </div>
</div> </div>
<div class="commentList"> <div class="commentList">
<board-comment v-for="comment in article.comment" :key="comment.no" :comment="comment" /> <BoardComment v-for="comment in article.comment" :key="comment.no" :comment="comment" />
</div> </div>
<div class="row gx-0"> <div class="row gx-0">
<div class="bg2 inputCommentHeader center d-grid"> <div class="bg2 inputCommentHeader center d-grid">
@@ -98,8 +98,8 @@ async function submitComment() {
} }
</script> </script>
<style> <style scoped>
td.text { .text {
white-space: pre; white-space: pre;
} }
</style> </style>
+3 -6
View File
@@ -15,17 +15,14 @@
</div> </div>
</div> </div>
</template> </template>
<script lang="ts"> <script setup lang="ts">
import type { BoardCommentItem } from "@/PageBoard.vue"; import type { BoardCommentItem } from "@/PageBoard.vue";
import { defineComponent, type PropType } from "vue"; import type { PropType } from "vue";
export default defineComponent({ defineProps({
name: "BoardComment",
props: {
comment: { comment: {
type: Object as PropType<BoardCommentItem>, type: Object as PropType<BoardCommentItem>,
required: true, required: true,
}, },
},
}); });
</script> </script>