Skip to content

Instantly share code, notes, and snippets.

Slow Steady

Kim Chanwoo kicombo

Slow Steady
  • Seoul, South Korea
View GitHub Profile
AnalyzePlatypus /
Last active Aug 5, 2021
Vue.js 2.7: Detect clicks outside an element (Close modals, popups, etc.)

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.