大家好,我使用 React 做一个搜索栏,并得到了一个程序,之前我在组件父 > 子、子 > 父之间传递数据,但现在我需要从我的 src>组件> 工具栏> 搜索栏传递到 src>容器>类别组件,有人可以帮助我吗?谢谢
最佳答案
实现此目的的另一种方法是创建和分派(dispatch)事件并将其列在组件中。
componentDidMount() {
this.nv.addEventListener("custom-event", this.handleNvEnter);
}
componentWillUnmount() {
this.nv.removeEventListener("custom-event", this.handleNvEnter);
}
handleNvEnter = (event) => {
console.log("custom-event:", event);
}
关于javascript - ReactJS 在组件之间传递数据(搜索栏),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52285495/