Answer the question
In order to leave comments, you need to log in
How to hide a block when clicking on any area?
There is a div. Opened by clicking on the link. Basic example.
Click here: (click to open, click to close) <a @click="isActive = !isActive">Ссылка</a>
Open this div:<div :class="{active: isActive}"></div>
data() {
isActive : false
}
Answer the question
In order to leave comments, you need to log in
data: () => ({
active: false,
}),
created() {
const onClick = e => this.active = this.$refs.block.contains(e.target) && this.active;
document.addEventListener('click', onClick);
this.$on('hook:beforeDestroy', () => document.removeEventListener('click', onClick));
},
<button @click.stop="active = !active">click me</button>
<div :class="{ active }" ref="block">hello, world!!</div>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question