Skip to content

Instantly share code, notes, and snippets.

@sliwey-zz
Created August 23, 2017 09:04
Show Gist options
  • Save sliwey-zz/2667d1c9ef97cbdcf6f5955677c6d206 to your computer and use it in GitHub Desktop.
Save sliwey-zz/2667d1c9ef97cbdcf6f5955677c6d206 to your computer and use it in GitHub Desktop.
clickOutside
import { getType } from '@/utils'
export const clickOutside = {
bind(el, binding, vnode, oldVnode) {
function handler(e) {
if (!el.contains(e.target) && getType(binding.value) === 'function') {
binding.value(e)
}
}
el.__handler__ = handler
document.addEventListener('click', handler)
},
unbind(el, binding, vnode, oldVnode) {
document.removeEventListener('click', el.__handler__)
delete el.__handler__
},
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment