Last active
December 7, 2018 03:59
-
-
Save vtno/88850dd3c9f84a2ade14f7dc3e19684a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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