html代码
<form onSubmit={this.submit.bind(this)}><input type="text" name="username" value={this.state.username} onChange={this.change.bind(this)} /><input type="password" name="password" value={this.state.password} onChange={this.change.bind(this)} /><button>提交</button></form>
js代码
change(ev) {console.log(ev);}
错误截图
当我想访问ev.target的时候为null,且会报错
解决方案
change(ev) {ev.persist()console.log(ev);}
解决效果
问题原因
出于性能原因,将重用此合成事件。如果您看到这一点,那么您正在访问已释放/取消的合成事件的属性“target”。设置为空。如果必须保留原始合成事件,请使用event.persist()
。
有关更多信息,请参考。