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

Category — 상품 카테고리

원문 보기 위키 갱신

상품 카테고리(분류)를 보여 주는 컴포넌트예요. 왼쪽 1차 분류를 고르면 오른쪽에 하위 분류가 표시되는, 쇼핑 앱 카테고리 화면의 전형적인 구조를 만들 수 있어요.

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

소개

상품 카테고리를 표시하기 위한 컴포넌트예요.

설치

import { createApp } from 'vue'
import { Category, CategoryPane } from '@nutui/nutui'

const app = createApp()
app.use(Category)
app.use(CategoryPane)

클래식 분류 모드

데이터 정의는 categoryData.js를 참고하세요.

:::demo

<template>
  <nut-category :category="data.category" @change="change">
    <nut-category-pane :categoryChild="data.categoryChild" @onChange="onChange"> </nut-category-pane>
  </nut-category>
</template>
<script setup>
import { reactive, toRefs, onMounted } from 'vue'
const data = reactive({
  categoryInfo: {},
  category: [{}],
  categoryChild: [{}]
})

onMounted(() => {
  setTimeout(() => {
    getData()
  }, 500)
})

const getData = () => {
  fetch('//storage.360buyimg.com/nutui/3x/categoryData.js')
    .then((response) => response.json())
    .then((res) => {
      const { categoryInfo, categoryChild } = res
      data.categoryInfo = categoryInfo
      data.category = categoryInfo.category
      data.categoryChild = categoryChild
    })
    .catch((err) => console.log('Oh, error', err))
}

const change = (index) => {
  data.categoryChild = [].concat(data.categoryInfo.category[index + 1].children)
}
const onChange = () => {
  console.log('Click on current category data')
}
</script>

:::

텍스트만 표시

:::demo

<template>
  <nut-category :category="data.category" @change="changeText">
    <nut-category-pane type="text" :categoryChild="data.categoryChild" @onChange="onChange"> </nut-category-pane
  ></nut-category>
</template>
<script setup>
import { reactive, toRefs, onMounted } from 'vue'
const data = reactive({
  categoryInfo: {},
  category: [{}],
  categoryChild: [{}]
})

onMounted(() => {
  setTimeout(() => {
    getData()
  }, 500)
})

const getData = () => {
  fetch('//storage.360buyimg.com/nutui/3x/categoryData.js')
    .then((response) => response.json())
    .then((res) => {
      console.log('res', res)
      const { categoryInfo, categoryChild } = res
      data.categoryInfo = categoryInfo
      data.category = categoryInfo.category
      data.categoryChild = categoryChild
    })
    .catch((err) => console.log('Oh, error', err))
}

const changeText = (index) => {
  data.categoryChild = [].concat(data.categoryInfo.category[index + 1].children)
}

const onChange = () => {
  console.log('Click on current category data')
}
</script>

:::

커스텀 분류

:::demo

<template>
  <nut-category @change="changeCustom"
    ><nut-category-pane type="custom" :customCategory="data.customCategory" @onChange="changeCustom">
    </nut-category-pane
  ></nut-category>
</template>
<script setup>
import { reactive, toRefs, onMounted } from 'vue'
const data = reactive({
  customCategory: [{}]
})
onMounted(() => {
  setTimeout(() => {
    getData()
  }, 500)
})
const getData = () => {
  fetch('//storage.360buyimg.com/nutui/3x/categoryData.js')
    .then((response) => response.json())
    .then((res) => {
      const { customCategory } = res
      data.customCategory = customCategory
    })
    .catch((err) => console.log('Oh, error', err))
}
const changeCustom = () => {
  console.log('Click to categorize data')
}
</script>

:::

API

Category Props

Attribute Description Type Default
type Classification mode: classify, text, custom string classify
category Left navigation bar data list Array []

Category Events

Event Description Arguments
change Classic classification, click on the left navigation bar to get the data list on the right Clicked data
change-text In text classification mode, click on the left navigation bar to get the data list on the right Input data
change-custom Customize, click the left navigation bar to get the data list on the right Current quantity

CategoryPane Props

Attribute Description Type Default
category-child The current classification data is displayed on the right Array []
custom-category Custom categorical data Array []

CategoryPane Events

Event Description Arguments
on-change Click on the right classified data trigger Clicked data

CategoryPane Slots

Name Description
default Custom content

테마 (Theming)

CSS 변수

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

Name Default Value
--nut-category-bg-color rgba(255, 255, 255, 1)
--nut-category-list-left-bg-color rgba(246, 247, 249, 1)
--nut-category-list-item-color var(--nut-title-color)
--nut-category-list-item-checked-color rgba(255, 255, 255, 1)
--nut-category-list-item-checked-img-bg-color var(--nut-primary-color)
--nut-category-pane-gray-color #666
--nut-category-pane-border-color rgb(153, 153, 153)
--nut-category-pane-title-color rgba(51, 51, 51, 1)

더 알아보기 (Learn more)

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