Check out example codes for "$emit in vue". It will help you in understanding the concepts better.
Code Example 1
<!--
VERY Simplified example
Our parent comp reference child comp
-->
<parent-comp>
<template>
<!-- Remember to add the callback to the child comp -->
<child-comp
@askParentToDoStuff="doStuff">
</child-comp>
</template>
<script>
methods() {
function doStuff(param) {
console.log('received: ', param);
// logs: received: 'foo'
}
}
</script>
</parent-comp>
<!-- Child comp -->
<child-comp>
<template>
<p>Im the child comp</p>
<button :click="myFunction('foo')">Click Me</button>
</template>
<script>
methods() {
function myFunction(param) {
// See the callback in the child comp reference
// in the parent comp
this.$emit('askParentToDoStuff', param);
}
}
</script>
</child-comp>
Learn ReactJs, React Native from akashmittal.com