Vue.js 2.0 appears to have a limitation where events cannot be emitted directly from a grand child component to its grand parent.
Vue.component('parent', {
template: '<div>I am the parent - {{ action }} <child @eventtriggered="performAction"></child></div>',
data(){
return {
action: 'No action'
}
},
methods: {
performAction() { this.action = 'actionDone' }
}
})
Vue.component('child', {
template: '<div>I am the child <grand-child></grand-child></div>'
})
Vue.component('grand-child', {
template: '<div>I am the grand-child <button @click="doEvent">Do Event</button></div>',
methods: {
doEvent() { this.$emit('eventtriggered') }
}
})
new Vue({
el: '#app'
})
A solution is provided in this JsFiddle https://jsfiddle.net/y5dvkqbd/4/, which involves emitting two events:
- Emitting an event from the grand child to a middle component
- Then emitting another event from the middle component to the grand parent
The need for this additional "middle" event may seem redundant and unnecessary. Is there a more direct way to emit an event to the grand parent that I may be overlooking?