I'm using Vue2.x and I want to add a event listener by using customising directives, however in vue1.x I can use the following code snippet:
Vue.directive('demo',{
bind () {
let self = this
this.event = function (event) {
self.vm.$emit(self.expression, event)
}
this.el.addEventListener('click', this.stopProp)
document.body.addEventListener('click', this.event)
}
})
but in vue2.x, I found that 'this' is always undefined, and I cannot figure out how to get the vm (Vue Instance) object. I've tried all the passed parameter list on documentation.
Does anyone know how to get access to the vm object?