<template>
<div id="accordion" class="accordion-container">
<div
v-for="(item, index) in items"
:key="index"
:class="[
'accordion',
{ 'is-open': isOpen.includes(index) }
]"
>
<div class="accordion-header" @click="toggleAccordion(index)">
{{ item.title }}
<i v-if="!isOpen.includes(index)" class="fal fa-plus"/>
<i v-else class="fal fa-minus"/>
</div>
<div class="accordion-body">
<div class="accordion-content">
{{ item.text }}
<strong>{{ item.sub }}</strong>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
name: "trial-page",
data() {
return {
items: [
{
title: "Accordion 1",
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
sub: "Pellentesque risus mi"
},
{
title: "Accordion 2",
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
sub: "Pellentesque risus mi"
},
{
title: "Accordion 3",
text: "Lorem ipsum dolor sit amet, consectetur adipiscing elit.",
sub: "Pellentesque risus mi"
}
],
isOpen: []
};
},
methods: {
toggleAccordion(index) {
if (this.isOpen.includes(index)) {
this.isOpen = this.isOpen.filter(i => i !== index);
return;
}
this.isOpen.push(index);
}
}
};
</script>
<style>
.accordion:not(.is-open) .accordion-body {
display: none;
}
</style>