请问这是哪里出问题了
来源:2-7 自由编程
Takm
2019-08-08 23:49:25
class Ref extends React.Component { constructor(props) { super(props); this.state = { } } handleClick() { console.log(this.input.value) } render() { return ( <React.Fragment> <div> <input type="text" ref={(input) => this.inputElem = input} /> </div> <button onClick={this.handleClick.bind(this)}>提交</button> </React.Fragment> ) } }
点击提交后出错:Uncaught TypeError: Cannot read property 'value' of undefined
是不是 this.handleClick.bind(this) 的.bind(this) 括号里不能为this?
1回答
同学你好,
是属性的问题,参考修改:
定义的属性要保持一致。可以重新测试下。
祝学习愉快!