1

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 :(

Dmitry Bubnenkov
  • 9,415
  • 19
  • 85
  • 145

1 Answers1

1

Just do following in template:

<template>
    <div class="Book" v-on:newchapter="foo">
        {{msg}}
    </div>
</template>
Saurabh
  • 71,488
  • 40
  • 181
  • 244