[英]React.js Unresolved variable in WebStorm
我在以下代码片段中遇到unresolved variable
问题:
constructor(props) {
super(props);
this.handleModalView = this.handleModalView.bind(this);
}
handleModalView() {
this.refs.temp.handleShow();
}
render() {
return (
<div className="App">
<ModalView ref = 'temp' />
<img src="some_image_source"
className="SettingsLogo" onClick={this.handleModalView}
/>
</div>
IDE在handleModalView()
显示了一个unresolved variable temp
。 但是,我的代码工作正常。
编辑1 :我已经包括了我编写的构造函数。 错误仍然存在。
您应该在组件类中创建一个构造函数并绑定所有成员函数:
class App extends Component {
constructor(props) {
super(props);
this.handleModalView = this.handleModalView.bind(this);
}
handleModalView() {
this.refs.temp.handleShow();
}
render() {
return (
<div className="App">
<ModalView ref = 'temp' />
<img src="some_image_source"
className="SettingsLogo" onClick={this.handleModalView}
/>
</div>)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.