Skip to content

Instantly share code, notes, and snippets.

Avatar
🦄
Remote

Noemi Leon noeleo25

🦄
Remote
View GitHub Profile
@AnalyzePlatypus
AnalyzePlatypus / vue-click-outside.md
Last active Dec 15, 2021
Vue.js 2.7: Detect clicks outside an element (Close modals, popups, etc.)
View vue-click-outside.md

Detecting outside clicks in Vue.js

See this StackOverflow thread

First off, include the directive at the end of this gist.

  1. On your open button, make sure to use @click.stop to prevent the open click event from closing your modal.
  2. On your modal, add the v-click-outside directive and points it at a function to call when clicked outside.

Example: