Skip to content

Instantly share code, notes, and snippets.

@vtno
Last active December 7, 2018 03:59
Show Gist options
  • Save vtno/88850dd3c9f84a2ade14f7dc3e19684a to your computer and use it in GitHub Desktop.
Save vtno/88850dd3c9f84a2ade14f7dc3e19684a to your computer and use it in GitHub Desktop.
/*
In this scenario you could just use `vm.$emit` to communicate to `Container` from `CustomButton.
In reality, this pattern will shine when your component is nested inside some more components and
you can't really emit event to the `Container` quite easily.
*/
<template>
<custom-button label='Click me and the I will update the container state' />
</template>
<script>
import { EventBus } from "./EventBus.js"
import CustomButton from "./CustomButton.vue"
export default {
 data () {
  return { buttonClickCount: 0 }
 },
 created () {
  EventBus.$on('my-custom-event', (params) => {
// you can submit data via params when emitting event.
console.log(params) 
this.buttonClickCount++ 
}
 },
 components: {
  'custom-button': CustomButton
 }
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment