리스트 페이지 정렬기준셀렉박스 추가

This commit is contained in:
kimdaae328 2025-01-17 13:19:41 +09:00
parent ae2dbd4992
commit 7f0f4ecabb
3 changed files with 83 additions and 57 deletions

View File

@ -11,7 +11,7 @@
/> />
</div> </div>
<!-- 게시물 내용 섹션 --> <!-- 게시물 내용 섹션 -->
<div class="col-md-10"> <div :class="contentColClass">
<div class="card-body"> <div class="card-body">
<!-- 태그 --> <!-- 태그 -->
<h6 class="badge rounded-pill bg-primary text-white mb-2"> <h6 class="badge rounded-pill bg-primary text-white mb-2">
@ -23,7 +23,7 @@
<p class="card-text str_wrap">{{ content }}</p> <p class="card-text str_wrap">{{ content }}</p>
<!-- 날짜 --> <!-- 날짜 -->
<div class="d-flex justify-content-between"> <div class="d-flex justify-content-between">
<small class="text-muted">{{ formatDate(date) }}</small> <small class="text-muted">{{ formattedDate }}</small>
<!-- 좋아요와 댓글 --> <!-- 좋아요와 댓글 -->
<div> <div>
<span class="text-muted me-3"> <span class="text-muted me-3">
@ -40,49 +40,56 @@
</div> </div>
</template> </template>
<script> <script setup>
export default { import { computed } from 'vue';
props: { import { defineProps } from 'vue';
img: {
type: String, // Props
default: null, const props = defineProps({
}, img: {
category: { type: String,
type: String, default: null,
required: true,
},
title: {
type: String,
required: true,
},
content: {
type: String,
required: true,
},
date: {
type: String,
required: true,
},
likes: {
type: Number,
default: 0,
},
comments: {
type: Number,
default: 0,
},
}, },
methods: { category: {
formatDate(dateString) { type: String,
const date = new Date(dateString); required: true,
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(
date.getDate()
).padStart(2, "0")} ${String(date.getHours()).padStart(2, "0")}:${String(
date.getMinutes()
).padStart(2, "0")}`;
},
}, },
}; title: {
type: String,
required: true,
},
content: {
type: String,
required: true,
},
date: {
type: String,
required: true,
},
likes: {
type: Number,
default: 0,
},
comments: {
type: Number,
default: 0,
},
});
// computed
const contentColClass = computed(() => {
return props.img ? 'col-md-10 col-12' : 'col-md-12';
});
// formattedDate computed
const formattedDate = computed(() => {
const date = new Date(props.date);
return `${date.getFullYear()}-${String(date.getMonth() + 1).padStart(2, "0")}-${String(
date.getDate()
).padStart(2, "0")} ${String(date.getHours()).padStart(2, "0")}:${String(
date.getMinutes()
).padStart(2, "0")}`;
});
</script> </script>
<style> <style>

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="input-group mb-3 d-flex"> <div class="input-group mb-3 d-flex">
<input type="text" class="form-control bg-white" placeholder="Search" @change="search" /> <input type="text" class="form-control" placeholder="Search" @change="search" />
<button type="button" class="btn btn-primary"><i class="bx bx-search bx-md"></i></button> <button type="button" class="btn btn-primary"><i class="bx bx-search bx-md"></i></button>
</div> </div>
</template> </template>

View File

@ -1,19 +1,40 @@
boardlist
<template> <template>
<div class="container-xxl flex-grow-1 container-p-y"> <div class="container-xxl flex-grow-1 container-p-y">
<!-- 검색 --> <!-- 상단 : 검색창, 정렬 셀렉트 박스, 글쓰기 버튼 -->
<search-bar @update:data="search" /> <div class="row mb-4">
<!-- 검색창 -->
<div class="col">
<search-bar @update:data="search" />
</div>
</div>
<!-- 리스트 --> <div class="row">
<div class="row g-3"> <!-- 정렬 셀렉트 박스 -->
<div class="mt-8"> <div class="col-md-3 mb-4">
<select class="form-select">
<option selected>정렬 기준 선택</option>
<option value="1">조회수</option>
<option value="2">날짜</option>
</select>
</div>
<!-- 글쓰기 버튼 -->
<div class="col-auto ms-auto mb-4">
<router-link to="/board/write"> <router-link to="/board/write">
<WriteButton /> <WriteButton />
</router-link> </router-link>
</div> </div>
</div>
<!-- 게시물 리스트 -->
<div class="row g-3">
<board-card :posts="paginatedList" @click="goDetail" /> <board-card :posts="paginatedList" @click="goDetail" />
</div>
<!-- 페이지네이션 -->
<div class="row g-3">
<!-- 페이지네이션 -->
<div class="mt-8"> <div class="mt-8">
<pagination <pagination
:current-page="currentPage" :current-page="currentPage"
@ -40,7 +61,6 @@ const searchText = ref('');
// //
const goDetail = (id) => { const goDetail = (id) => {
console.log('Navigating to ID:', id)
router.push({ name: 'BoardDetail', params: { id } }); router.push({ name: 'BoardDetail', params: { id } });
}; };
@ -82,7 +102,6 @@ const changePage = (page) => {
// //
const fetchPosts = async () => { const fetchPosts = async () => {
const response = await axios.get("board/general"); const response = await axios.get("board/general");
console.log(response.data.data.list)
if (response.data && response.data.data && Array.isArray(response.data.data.list)) { if (response.data && response.data.data && Array.isArray(response.data.data.list)) {
list.value = response.data.data.list.map((post, index) => ({ list.value = response.data.data.list.map((post, index) => ({
@ -93,7 +112,7 @@ const fetchPosts = async () => {
comments: post.comments || 0, comments: post.comments || 0,
})); }));
} else { } else {
console.error("Unexpected API response structure:", response.data); console.error("데이터 오류:", response.data);
} }
}; };