zhengyiming
昨天 25708e3f81956c1517f495e3303a6c8d08bb730c
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
59
<template>
  <div class="nut-category">
    <div class="nut-category__cateList">
      <div v-if="type == 'classify' || type == 'text'">
        <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.catName }}
          </div>
        </div>
      </div>
 
      <slot></slot>
    </div>
  </div>
</template>
 
<script setup lang="ts">
import { ref } from 'vue';
 
defineOptions({
  name: 'ProCategory',
});
 
type CategoryType = {
  catName?: string;
  [key: string]: any;
};
 
type Props = {
  type?: 'classify' | 'text' | 'custom';
  category?: CategoryType[];
};
 
const props = withDefaults(defineProps<Props>(), {
  type: 'classify',
  category: () => [],
});
 
const emit = defineEmits<{
  (e: 'change', index: number): void;
}>();
 
const checkIndex = ref(0);
const categoryLeft = ref(false); //是否显示slot
 
const getChildList = (index: number) => {
  checkIndex.value = index;
  emit('change', index);
};
 
defineExpose({ getChildList });
</script>