Skip to content

POST

  • 게시글을 선택하고 게시글 목록을 가져올 수 있어요.
  • 게시글 슬라이더, 추천 게시글, 인기 게시글 등을 표시하는 블록에 사용할 수 있어요.
html
<template>
  <!-- 게시글 목록 -->
  {{#each property.posts.data}}
    <div class="post">
      <span class="post-title">{{title}}</span>
      <span class="post-author">{{displayName}}</span>
      <span class="post-date">{{datetime createdDate}}</span>

      <!-- 조회 수 -->
      <span class="post-view-count">조회 {{viewCount}}</span>

      <!-- 좋아요 수 및 접속자 좋아요 여부 확인 -->
      <span class="like-count {{#if liked}}liked{{/if}}">♥ {{likeCount}}</span>
    </div>
  {{else}}
    <p>게시글이 없어요.</p>
  {{/each}}

  <button class="more-btn">다음 페이지</button>
</template>

<script>
  const container = bm.container;

  container.addEventListener('click', (event) => {
    // 다음 페이지
    if (event.target.matches('.more-btn')) {
      event.preventDefault();
      const currentPage = bm.config('property:posts.page');
      bm.config('property:posts.page', currentPage + 1);
      return bm.apply();
    }
  });
</script>
jsx
"posts": {
  "data": [                     // 게시글 목록
    {
      "id": 1,                   // 게시글 ID
      "title": "게시글 제목",     // 게시글 제목
      "contents": "<p>내용</p>",  // 게시글 본문
      "displayName": "김**",      // 작성자 표시명
      "isNotice": false,         // 공지글 여부
      "status": "PUBLIC",        // 게시글 상태 (예: "PUBLIC", "PRIVATE")
      "accessType": "OPEN",      // 접근 타입 (예: "OPEN", "SECRET")
      "authorType": "ADMIN",     // 작성자 타입 (예: "ADMIN", "MEMBER", "GUEST")
      "commentsCount": 3,        // 댓글 개수
      "attachmentsCount": 1,     // 첨부파일 개수
      "thumbnails": [            // 첨부파일 썸네일 목록 (있는 경우)
        "https://example.org/thumbnail.png"
      ],
      "viewCount": 0,            // 게시글 조회 수
      "liked": false,            // 접속자 기준 좋아요 여부
      "likeCount": 0,            // 게시글 좋아요 수
      "tags": [                  // 게시글 할당 태그(카테고리) 목록
        {
          "id": 1,
          "name": "공지"
        }
      ],
      "createdDate": "2023-11-02T02:24:16.388791" // 게시글 작성일시
    }
  ],
  "count": 35                   // 총 게시글 개수
}

bm.config()

bm.config()를 통해 데이터를 가져오는 방식을 설정할 수 있어요.

js
bm.config('property:posts.page', page); // 페이지 번호 설정
bm.config('property:posts.limit', limit); // 가져올 게시글 개수 설정
bm.config('property:posts.sort', sort); // 정렬 설정 (예: 'createdDate', 'createdDate,desc', 'likeCount', 'likeCount,desc', 'viewCount', 'viewCount,desc')
bm.config('property:posts.viewCountMin', value); // 조회 수 최솟값 필터
bm.config('property:posts.viewCountMax', value); // 조회 수 최댓값 필터
bm.config('property:posts.likeCountMin', value); // 좋아요 수 최솟값 필터
bm.config('property:posts.likeCountMax', value); // 좋아요 수 최댓값 필터
bm.config('property:posts.createdDateMin', value); // 작성일 시작 필터 (ISO8601)
bm.config('property:posts.createdDateMax', value); // 작성일 종료 필터 (ISO8601)
bm.config('property:posts.searchKeyword', value); // 제목 키워드 검색 필터
bm.config('property:posts.tagIds', value); // 태그 필터 (예: '1' 또는 '1,2,3')

Sixshop Developers Portal