Answer the question
In order to leave comments, you need to log in
How to catch in Vue click outside the element?
Something turned me on.
There is a component, it has a method toggleDropdown()
, it perfectly opens and closes my dropdan. When you click on the elements, everything is clear, v-on:click.stop="toggleDropdown"
but what to do when the click should be obeyed by anyone? I try like this:
created() {
document.addEventListener('click', function () {
this.toggleDropdown();
});
},
Answer the question
In order to leave comments, you need to log in
document.addEventListener('click', () => this.toggleDropdown());
document.addEventListener('click', this.toggleDropdown.bind(this));
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question