Created
June 13, 2020 20:38
-
-
Save Bachana123/683100f0a951c55bb60089d6c30bff33 to your computer and use it in GitHub Desktop.
mousedown, click outside
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Vue from 'vue' | |
Vue.directive('mouse-down', { | |
bind: function (el, binding, vnode) { | |
el.clickOutsideEvent = function (event) { | |
// here I check that click was outside the el and his childrens | |
if (!(el == event.target || el.contains(event.target))) { | |
// and if it did, call method provided in attribute value | |
vnode.context[binding.expression](event); | |
} | |
}; | |
document.body.addEventListener('mousedown', el.clickOutsideEvent) | |
}, | |
unbind: function (el) { | |
document.body.removeEventListener('mousedown', el.clickOutsideEvent) | |
}, | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment