Hi I'm playing around with vue directives and I'm trying to prevent click event if the element is <a>
or <button>
tag. So my question is, is this possible to do using vue directive?
Html
<a
@click.stop.prevent="displayModal()"
v-noclick="test">
I'm a link
</a>
Vue directive
Vue.directive('noclick', {
bind( elem, binding, vnode ) {
let user = {'name': 'John Doe'}
if( user ) {
let hasAccess = false
if( !hasAccess ) {
if( elem.tagName === 'A' ) {
elem.addEventListener( 'click', ( event ) => {
//this should prevent the element on click event
//but not working
event.stopPropagation()
event.preventDefault()
event.stopImmediatePropagation()
return false
})
return true
}
}
}
}
}