I am trying to pass a click method as a prop to my component's child's child. However, it seems like it works fine if the method doesn't take any parameters. However, if it takes parameters, Vue.js sends me a Invalid handler for event "click": got undefined error.
Here's my top-level component:
new Vue({
el: '#app',
created: function () {
},
methods: {
action1: function () {
console.log('--action 1--')
},
action2: function (word) {
console.log('--action 2--', word)
}
}
});
Here's my child component:
Vue.component('parent-component', {
template: '#parent-component',
data () {
return {
menuItems: [
{
label: 'Action 1',
onClick : this.action1
},
{
label: 'Action 2',
onClick : this.action2('two')
}
]
}
},
props: ['action1', 'action2']
});
<template id="parent-component">
<action-menu :actions="menuItems"></action-menu>
</template>
And here is my lowest level component:
Vue.component('action-menu', {
template: '#action-menu',
props: ['actions'],
});
<template id="action-menu">
<div>
<div v-for="action in actions">
<button @click="action.onClick">{{ action.label }}</button>
</div>
</div>
</template>
Here is my fiddle - http://jsfiddle.net/11sfg1p8/ - notice how the first button works, but the second button doesn't and the only difference is the second button takes a parameter. Anyone have any idea what's going on?
Thanks in advance!