As the title suggests, I am trying to pass a method from a parent component to a child component.
For example,
App.html
<div>
<TodoItem
done={todo.done}
toggle={toggle}
/>
</div>
<script>
import TodoItem from './TodoItem.html';
export default {
components: {
TodoItem,
},
methods: {
toggle(index) {
console.log(index);
},
},
};
</script>
TodoItem.html
<div>
<button on:click="toggle(0)"></button>
</div>
<script>
export default {
methods: {
toggle(index) {
// a guess. this works if you pass in console.log
this.options.data.toggle(index)
},
},
};
</script>
The desired functionality is that TodoItem calls the parent's method with its data.
This example breaks, the console logs TypeError: this.options.data.toggle is not a function
.
<button>
? – Elephant