在Vue.js中将方法从父组件传递到子组件 [英] Pass method from parent component to child component in vuejs
本文介绍了在Vue.js中将方法从父组件传递到子组件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人可以帮助我将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']
有人可以帮忙吗?
提前谢谢!
推荐答案
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>"
这篇关于在Vue.js中将方法从父组件传递到子组件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文