在子组件中,可在事件函数中将自定义事件名注入到props中,父组件进行监听,代码如下
子组件代码:
class Child extends Component{
toParent(params){
this.props.toParent(params)
}
render() {
return <View onClick="toParent.bind(this,params)">子组件</View>
}
}
父组件代码:
class Parent extends Component{
toParent(params){
console.log('子组件传过来的参数',params)
}
render() {
return (
<Child toParent.bind(this)></Child>
)
}
}