vuejs 父组件向子组件传递方法 [英] Pass method from parent component to child component in vuejs
本文介绍了vuejs 父组件向子组件传递方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以帮我在 vue.js 中将方法从父组件传递给子组件吗?我一直在尝试通过将方法作为道具传递来实现...
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...
我的父组件片段:
methods: {
test: function () {
console.log('from test method')
}
}
<template>
<child-component test="test"><child-component>
</template>
子组件片段
created: {
this.test() //returns test is not a function
},
props: ['test']
有人可以帮忙吗?
提前致谢!
推荐答案
您正在尝试将函数作为文字传递,如描述 此处.您最终将 test
道具设为 String... 您应该使用 :
来表示动态绑定,如下所示:
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:
这篇关于vuejs 父组件向子组件传递方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文