본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

Comment — 상품 후기

원문 보기 위키 갱신

상품 리뷰(댓글) 목록을 보여 주는 컴포넌트예요. 사용자 정보, 별점, 후기 내용에 사진·동영상 첨부와 추가 후기(추평)까지 하나의 카드로 구성해 줘요.

출처: Comment — doc.en-US.md

소개

댓글 목록을 표시할 때 사용해요.

설치

import { createApp } from 'vue'
import { Comment } from '@nutui/nutui'

const app = createApp()
app.use(Comment)

한 줄 이미지

기본적으로 상품 리뷰의 이미지는 한 줄 슬라이드로 표시돼요.

:::demo

<template>
  <nut-comment
    :images="cmt.images"
    :videos="cmt.videos"
    :info="cmt.info"
    @click="handleclick"
    @clickImages="clickImages"
    :operation="['replay']"
  >
    <template #comment-labels>
      <img
        class="nut-comment-header__labels--item"
        src="https://img11.360buyimg.com/imagetools/jfs/t1/211858/17/4258/12101/618e6f78Ed0edcadc/e83a673555edf59f.jpg"
      />
    </template>
  </nut-comment>
</template>
<script setup>
import { reactive, ref, onMounted } from 'vue'
let cmt = ref({})
onMounted(() => {
  fetch('//storage.360buyimg.com/nutui/3x/comment_data.json')
    .then((response) => response.json())
    .then((res) => {
      cmt.value = res.Comment
    })
    .catch((err) => console.log('Oh, error', err))
})
const handleclick = (info) => {
  console.log('进行跳转', info)
}
const clickImages = (imgs) => {
  console.log('进行图片展示', imgs)
}
</script>

:::

여러 줄 이미지

headerType 값을 이용하면 이미지를 여러 줄로 표시하도록 설정할 수 있어요.

:::demo

<template>
  <nut-comment
    headerType="complex"
    imagesRows="multi"
    :images="cmt.images"
    :videos="cmt.videos"
    :info="cmt.info"
    ellipsis="6"
    @clickImages="clickImages"
  >
    <template #comment-labels>
      <img
        class="nut-comment-header__labels--item"
        src="https://storage.360buyimg.com/imgtools/78925d9440-f9e874d0-e93d-11eb-8e5c-0da9e18a13b1.png"
        style="height: 12px"
      />
    </template>

    <template #comment-shop-reply>
      <div class="nut-comment-shop">
        <span>京东美妆国际:</span
        >尊敬的客户您好,非常抱歉给您带来不愉快的购物体验,关于过敏,什么成分都不存在个别性和普遍性。
      </div>
    </template>
  </nut-comment>
</template>
<script setup>
import { reactive, ref, onMounted } from 'vue'
let cmt = ref({})
onMounted(() => {
  fetch('//storage.360buyimg.com/nutui/3x/comment_data.json')
    .then((response) => response.json())
    .then((res) => {
      cmt.value = res.Comment
    })
    .catch((err) => console.log('Oh, error', err))
})
const clickImages = (imgs) => {
  console.log('进行图片展示', imgs)
}
</script>

:::

추가 후기 (추평)

:::demo

<template>
  <nut-comment
    imagesRows="multi"
    :images="cmt.images"
    :videos="cmt.videos"
    :info="cmt.info"
    :follow="cmt.follow"
    @clickImages="clickImages"
  ></nut-comment>
</template>
<script setup>
import { reactive, ref, onMounted } from 'vue'
let cmt = ref({})
onMounted(() => {
  fetch('//storage.360buyimg.com/nutui/3x/comment_data.json')
    .then((response) => response.json())
    .then((res) => {
      cmt.value = res.Comment
    })
    .catch((err) => console.log('Oh, error', err))
})
const clickImages = (imgs) => {
  console.log('进行图片展示', imgs)
}
</script>

:::

API

Props

Attribute Description Type Default
header-type Header type string default
images-rows Comment picture shows type of lines string one
ellipsis Ellipsis number string | number 2
videos Videos data Array []
images Images data Array []
info Comment data object {}
follow Additional review data object {}
operation Bottom button Array ["replay", "like", "more"]

Events

Event Description Arguments
click-operate Emitted when to click bottom button type
click Emitted when to click comment type
click-images Emitted when to click images or videos {type,index,value}

Slots

일부 영역이 슬롯으로 정의되어 있어서, 필요에 따라 교체할 수 있어요.

Name Description
comment-labels Comment user label
comment-shop-reply At the bottom of the comment is the display of the merchant's response

images 데이터

const images = [
  {
    smallImgUrl: '', // Small picture, used for table presentation
    bigImgUrl: '', // Big picture, big picture display use
    imgUrl: '' // Out figure
  }
]

videos 데이터

const videos = [
  {
    mainUrl: '', // Video mask image
    videoUrl: '' // Video url
  }
]

info 데이터

const info = {
  content: '', // Comment on the details
  nickName: '', // The name of the reviewer
  score: 5, // Number of comment stars
  avatar: '', // The avatar of the reviewer
  time: '', // Comment time
  size: '', // Comment good size
  replay: 23, // Number of replies to this comment
  like: 1 // Number of likes for this comment
}

follow 데이터

추가 후기(추평) 관련 정보를 담는 데이터예요.

const follow = {
  days: 0, // Review how many days after purchase
  content: '', // Review content
  images: [] // Review images
}

테마 (Theming)

CSS 변수

이 컴포넌트는 스타일을 커스터마이징할 때 쓸 수 있는 CSS 변수를 제공해요. 자세한 내용은 ConfigProvider 컴포넌트 문서를 참고하세요.

Name Default Value
--nut-comment-header-user-name-color rgba(51, 51, 51, 1)
--nut-comment-header-time-color rgba(153, 153, 153, 1)
--nut-comment-bottom-label-color rgba(153, 153, 153, 1)
--nut-comment-shop-color var(--nut-primary-color)

더 알아보기 (Learn more)

이 문서는 NutUI v4 공식 영문 문서를 한국어로 옮긴 글이에요. 최신 API와 변경 사항은 원문에서 확인하는 게 가장 정확해요.