I can't understand how to emit event from directive
This is my template where i try to call method :
<tooltip v-click-outside="clickEvent" v-on:emitedEvent="clickEvent"></tooltip>
From v-click-outside="clickEvent" i got:
Property or method "clickEvent" is not defined on the instance but referenced during render.
My code:
export default {
data() {
return {
}
},
methods: {
clickEvent: function () {
console.log('click')
}
},
}
Vue.directive('click-outside', {
bind: function (el, binding, vnode) {
el.event = function (event) {
if (!(el.contains(event.target))) {
vnode.context.$emit('emitedEvent')
}
}
document.addEventListener('click', el.event)
},
unbind: function (el) {
document.removeEventListener('click', el.event)
},
})
I get:
Invalid handler for event "emitedEvent": got undefined