I have a list of items, and I want to feed its data from a JavaScript array:
// HTML
<ul
<li v-for="menuItem in menuItems">
<a @click="menuItem.action">{{ menuItem.name }}</a>
</li>
</ul>
// DATA
data () {
return {
menuItems: [
{ name: 'Split up', action: this.split('up') },
{ name: 'Split down', action: this.split('down') },
{ name: 'Split left', action: this.split('left') },
{ name: 'Split right', action: this.split('right') }
]
}
// METHODS
methods: {
split (direction) {
store.actions.openWindow(direction)
store.actions.closeMenu()
}
}
But right now I get this error:
[Vue warn]: v-on:click="menuItem.action" expects a function value, got undefined
Meaning that I'm passing the value of action wrongly.
What's the correct way of doing it?