问题的根源
this.refs.list是React组件,而不是DOM节点。要获取具有
addEventListener()方法的DOM元素,您需要调用
ReactDOM.findDOMNode():
class ScrollingApp extends React.Component { _handleScroll(ev) { console.log("Scrolling!"); } componentDidMount() { const list = ReactDOM.findDOMNode(this.refs.list) list.addEventListener('scroll', this._handleScroll); } componentWillUnmount() { const list = ReactDOM.findDOMNode(this.refs.list) list.removeEventListener('scroll', this._handleScroll); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)