export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.directive('detect-click-outside', {
mounted (el) {
el.clickOutsideEvent = function (event) {
// // here I check that click was outside the el and his children
if (!(el == event.target || el.contains(event.target))) {
// and if it did, change data from directive
console.log("click is inside")
}
console.log("click is outside")
// update a value (name: clickedOutside) in the component
// where this directive is used
};
document.body.addEventListener('click', el.clickOutsideEvent)
},
})
})
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.directive('detect-click-outside', {
mounted (el) {
el.clickOutsideEvent = function (event) {
// // here I check that click was outside the el and his children
if (!(el == event.target || el.contains(event.target))) {
// and if it did, change data from directive
console.log("click is inside")
}
console.log("click is outside")
// update a value (name: clickedOutside) in the component
// where this directive is used
};
document.body.addEventListener('click', el.clickOutsideEvent)
},
})
})