BaseAccordion.vue
<template>
<div class="wrapper">
<div class="accordion">
<input type="checkbox" @click="toggleItem" />
<h2 class="title">
<slot name="title"></slot>
</h2>
</div>
<div v-show="show" class="content">
<slot name="content"></slot>
</div>
</div>
</template>
<script>
export default {
components: {},
data: function () {
return {
show: false,
};
},
methods: {
toggleItem: function () {
this.show = !this.show;
},
},
};
</script>
<style scoped>
.wrapper {
margin: 0 auto;
width: 300px;
padding: 10px;
}
.accordion {
display: flex;
cursor: pointer;
margin: 0;
}
.title {
margin: 0;
color: darkgreen;
}
.content {
text-align: left;
width: 100%;
border-bottom: 1px solid black;
padding: 10px;
}
</style>
Issue detected in the code above is that,
When attempting to loop through a list inside another list (using nested v-for loops),
I am encountering each value being repeated multiple times, leading to duplicated sub items due to repetitive item display.