zhengyiming
2025-02-13 20619871d0db98f3f298a04e200005e84e0bc6be
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<template>
  <div class="nut-category">
    <div class="nut-category__cateList">
      <scroll-view :scroll-y="true" class="nut-category__cateList-scroll">
        <div v-for="(item, index) in category" :key="index" class="nut-category__cateListLeft">
          <div
            :class="[
              checkIndex == index
                ? 'nut-category__cateListItemChecked'
                : 'nut-category__cateListItem',
            ]"
            @click="getChildList(index)"
          >
            {{ item.name }}
          </div>
        </div>
      </scroll-view>
      <slot></slot>
    </div>
  </div>
</template>
 
<script setup lang="ts">
import { PropType, ref } from 'vue';
 
defineOptions({
  name: 'Category',
});
 
type CategoryType = {
  name?: string;
  [key: string]: any;
};
 
const props = defineProps({
  //左侧导航栏
  category: {
    type: Array as PropType<CategoryType>,
    default: () => [],
  },
 
  defaultIndex: {
    type: Number,
    default: 0,
  },
});
 
const emit = defineEmits<{
  (e: 'change', index: number): void;
}>();
 
const checkIndex = ref(props.defaultIndex);
 
const getChildList = (index: any) => {
  checkIndex.value = index;
  emit('change', index);
};
</script>