Answer the question
In order to leave comments, you need to log in
How to close all components (folders) when clicking on any of them or on a nested element?
The application looks like a list of folders with items inside. Clicking on a folder opens a list of items.
Both the folder and the elements are separate components for me.
And it turns out that when you click on any element or folder, other folders do not know about it. And it turns out that several folders are open and until you click them all, they will not close. Uncomfortable.
But I can't figure out how to tell all folder components that there was a click and it's time to close them.
Some code for understanding:
//Контейнер который содержит папки
<div v-for="currentBk of bkFolder"
:key="currentBk.id"
>
<BkFolder v-if="currentBk.children"
:bkChildren = currentBk.children
:title = currentBk.title
:index = currentBk.index
>
</BkFolder>
<BkItem v-else
:currentBk = currentBk
>
</BkItem>
</div>
//*************** Вывод папок
<template>
<div>
<div v-if="index < 4"
v-on:click="setOpenFolder"
class="bk-folder">
{{ title }}
</div>
<BkOpenFolder
v-if="openFolder"
v-on:click="setOpenFolder"
:bkChildren = bkChildren
/>
</div>
</template>
//********** Раскрытая папка с вложенными элементами
<template>
<div
v-if="openFolder"
v-on:click="setCloseFolder"
>
<div class="title">
{{ title }}
</div>
<div
class="bk-open-folder"
>
<div v-for="currentBk of bkChildren"
:key="currentBk.id"
>
<BkFolder v-if="currentBk.children"
:bkFolder = currentBk.children
:title = currentBk.title
>
</BkFolder>
<BkItem v-else
:currentBk = currentBk
>
</BkItem>
</div>
</div>
</div>
</template>
Answer the question
In order to leave comments, you need to log in
Any click outside the component is caught and some kind of handler is launched.
https://github.com/ndelvalle/v-click-outside
https://github.com/nchutchind/vue-outside-events
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question