Skip to content

Category 商品分类

介绍

用于展示商品分类的组件。

基础用法

data 数据格式可参考 categoryData.js

vue
<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import { categoryInfo, categoryChild } from './data'

const category = ref([])
const categoryChild = ref([])

onMounted(() => {
  category.value = categoryInfo.category
  categoryChild.value = categoryChild
})

const change = (index: number) => {
  categoryChild.value = [].concat(category.value[index].children)
}

const onChange = () => {
  console.log("当前分类数据")
}
</script>

<template>
  <nut-category :category="category" @change="change">
    <nut-category-pane :categoryChild="categoryChild" @onChange="onChange" />
  </nut-category>
</template>

自定义分类

vue
<script lang="ts" setup>
import { ref, onMounted } from 'vue'
import { customCategory } from './data'

const customCategoryData = ref([])

onMounted(() => {
  setTimeout(() => {
    customCategoryData.value = customCategory
  }, 500)
})

const changeCustom = () => {
  console.log('点击分类数据')
}
</script>

<template>
  <nut-category @change="changeCustom">
    <nut-category-pane
      type="custom"
      :customCategory="customCategoryData"
      @onChange="changeCustom"
    />
  </nut-category>
</template>

API

Props

参数说明类型可选值默认值
type分类模式stringclassify / text / custom'classify'
category左侧导航栏数据列表Array-[]

Events

事件名说明类型
change点击左侧导航栏时触发(index: number) => void

CategoryPane Props

参数说明类型可选值默认值
category-child右侧展示当前分类数据Array-[]
custom-category自定义分类数据Array-[]

CategoryPane Events

事件名说明类型
on-change点击右侧分类数据触发(item: any) => void

CategoryPane Slots

名称说明
default自定义内容

主题定制

样式变量

组件提供了下列 CSS 变量,可用于自定义样式,使用方法请参考 ConfigProvider 组件

名称默认值
--nut-category-bg-colorrgba(255, 255, 255, 1)
--nut-category-list-left-bg-colorrgba(246, 247, 249, 1)
--nut-category-list-item-colorvar(--nut-title-color)
--nut-category-list-item-checked-colorrgba(255, 255, 255, 1)
--nut-category-list-item-checked-img-bg-colorvar(--nut-primary-color)
--nut-category-pane-gray-color#666
--nut-category-pane-border-colorrgb(153, 153, 153)
--nut-category-pane-title-colorrgba(51, 51, 51, 1)

MIT Licensed