I'm creating a button component in VueJS. I've made a dynamic event with a prop, plus event function and params as props as well. That works fine, the parent can set whatever event to trigger a method. However I want to be able to set modifiers on that event as well but don't see a way to do that. Is it possible?
The button component:
<button class="btn" :class="[styles, cssClasses]" role="button"
@[event]="onEvent(eventParams)"
:disabled="disabled">
<slot></slot>
</button>
The parent:
<Button
:event="'click'"
:onEvent="logEvent"
:eventParams="'This is a test message'">Test button</Button>
Adding a static modifier to the dynamic event works @[event].prevent=... but I want to be able to set the modifier from a prop, or not have it at all.
I also tried setting up an event listeners object but can't see a way to add modifiers to those either. At least in this option I can pass the event and preventdefault the old fashioned way, like our grandparents did.
moveAllListeners() {
const me = this
return Object.assign({},
this.$listeners,
{
click(e) {
e.preventDefault()
me.moveAll()
},
mouseenter(e) {
console.log('Mouse entered');
}
}
)
}