I
I
Intelix2022-01-16 10:52:17
Vue.js
Intelix, 2022-01-16 10:52:17

How to hide an element when clicking on it and clicking outside of it vue?

There is a select, it is necessary that the first time you click on it, it opens, the second time it hides, and it also hides when you click outside it.

I did the first and last point, but because of the hook:

mounted() {
    document.addEventListener("click", this.hideSelect.bind(this), true)
  }

Hiding on a repeated click stops working, which I have implemented through the variable @click="selectListShow = !selectListShow"

How to fix it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey delphinpro, 2022-01-16
@Intelix

https://yandex.ru/search/?clid=1882628&text=vue+cl...
https://qna.habr.com/q/700194

A
Alex, 2022-01-16
@Kozack Vue.js

In this.hideSelectyou need to check not just where exactly the user clicked.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question