AccordionItem.vue
2.11 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<template>
<div class="accordion-item">
<div v-if="hasChildren" class="accordion-header" @click="toggle" :style="item.style">
{{ item.category_name }}
<i v-if="!isOpen" class="el-icon-arrow-right"></i><i v-else class="el-icon-arrow-down"></i>
</div>
<div v-else class="list-item" @click="goToDetail(item)">
{{ item.category_name }}
</div>
<el-collapse-transition>
<div v-if="isOpen || !hasChildren" class="accordion-content">
<p v-if="!hasChildren">{{ item.content }}</p>
<AccordionItem v-for="child in item.children" :key="child.id" :item="child" />
</div>
</el-collapse-transition>
</div>
</template>
<script>
export default {
name: 'AccordionItem',
props: {
item: {
type: Object,
required: true
}
},
data() {
return {
isOpen: false
};
},
computed: {
hasChildren() {
return this.item.children && this.item.children.length > 0;
}
},
methods: {
toggle() {
if (this.hasChildren) {
this.isOpen = !this.isOpen;
}
},
goToDetail (v) { // 跳转产品详情
this.$router.push({
path: '/product/detail',
query: {
id: v.id,
}
});
}
}
};
</script>
<style scoped>
.accordion-item {
/* border-bottom: 1px solid #ccc; */
}
.accordion-header {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
justify-content: space-between;
height: 3rem;
line-height: 1;
background-color: #FFF;
color: #303133;
cursor: pointer;
/* border-bottom: 1px solid #EBEEF5; */
font-size: 0.9rem;
font-weight: 500;
-webkit-transition: border-bottom-color .3s;
transition: border-bottom-color .3s;
outline: 0;
}
.list-item {
font-size: 0.85rem;
line-height: 2;
/* padding: 10px; */
/* background-color: #f0f0f0; */
font-weight: normal;
cursor: default;
&:hover {
text-decoration: underline;
cursor: pointer;
}
}
.accordion-content {
padding-left: 0.5rem;
background-color: #fff;
}
</style>