@output EventEmitter在反应中没有等效的方法。执行此操作的标准方法是将props中的回调传递给子组件。像这样:
class Parent extends React.Component {
handleChildClicked = () => {
console.log('child clicked');
}
render() {
<Child onClick={this.handleChildClicked} />
}
}
const Child = (props: Props) => {
const { onClick } = props;
return (
<button onClick={onClick}>Clicky!</button>
);
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1052 次 |
| 最近记录: |