Can someone help me with passing a method from a parent to a child component in vue.js? I've been trying to do it by passing the method in as a prop...
My parent component snippet:
methods: {
test: function () {
console.log('from test method')
}
}
<template>
<child-component test="test"><child-component>
</template>
Child component snippet
created: {
this.test() //returns test is not a function
},
props: ['test']
Can someone help?
Thanks in advance!
Call Child Component method from Parent Component A ViewChild is a decorator which is used when we want to access a child component inside the parent component, we use the decorator @ViewChild() in Angular.
You are trying to pass a function as literal as described here. You end up with test
prop being String... You should use :
to indicate dynamic binding as follows:
<child-component :test="test"><child-component>"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With