react this.refs.method is not a function
父组件
<Menu.Item key="change_pwd">
<ChangePwd ref="Changepwd" />
</Menu.Item>
handleMenuClick = (item) => {
console.log(item.key)
if (item.key == "logout") {
this.handleLogout()
}
if (item.key == "change_pwd") {
console.log(this.refs.Changepwd)
// this.refs.Changepwd.childMethod()
}
}
子组件
childMethod() {
alert("组件之间通信成功");
}
输出react this.refs.childMethod is not a function
为啥找不到子组件的方法呢
打印出来的this.refs.Changepwd如图并没有自己定义的method
this.refs.Changepwd 是获取到的这个实体 Dom, 并不是一个方法。