Adding Click Event To Component - gecko-8/devwiki GitHub Wiki
Say you want to create a custom button component and pass the click event to a contained button control.
- Add a click event to your contained button and add a handler method to it.
<template> <button @click="onClick"> <slot></slot> </button> </template> <script> export default { methods: { onClick() { // Next step will be added here } } } </script>
- Emit a click event at the spot indicated above.
<script> export default { methods: { onClick() { this.$emit('click'); } } } </script>
- Handle it as usual wherever you use your component.
@click="onClick"