I need to pass data from children to parent component. Code is very simple, but I can't understand what and where I am missing.
export default {
name: 'TableOfContent',
props: ['itemGUID'], // is it nessosary?
methods: {
itemClick(itemGUID)
{
console.log(itemGUID);
this.$emit('newchapter', itemGUID) // passing GUID to parent
}
}
}
Parent template:
<template>
<div class="Book" v-on:newchapter="foo(itemGUID)">
{{msg}}
</div>
</template>
<script>
import toc from './TableOfContent.vue'
export default {
name: 'mybook',
data () {
return {
msg: 'my main book'
}
},
methods:
{
foo(itemGUID)
{
console.log("GUID is: ", itemGUID);
}
},
components: {toc}
}
</script>
This code do not work :(