Skip to content

Instantly share code, notes, and snippets.

@rebz
Created April 13, 2019 20:28
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Custom directive to drop in a project for Modal-esque elements.
/*
* Add `v-click-outside="function"` to your element.
* Does not take into account 'touchstart'
*/
export default {
bind: function (el, binding, vnode) {
el.event = function (event) {
if (!(el == event.target || el.contains(event.target))) {
vnode.context[binding.expression](event);
}
}
document.body.addEventListener('click', el.event)
},
unbind: function (el) {
document.body.removeEventListener('click', el.event)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment