我在组件的渲染方法中有这个 div
<div ref={node => this.domNode = node} style={this.getStyle()}>{ this.props.children }</div>
当我在 componentDidMount 中执行此操作时
this.domNode.addEventListener('mousedown', this.onDrag);
有错误
this.domNode.addEventListener is not a function
最佳答案
你必须在它周围放置一个 ReactDOM.findDOMNode 。
componentDidMount = () => {
ReactDOM.findDOMNode(this.domNode).addEventListener('mousedown', this.onDrag);
}
关于reactjs - react : addEventListener is not a function error,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39310754/