javascript - WebStorm 中的 React.js 未解析变量
问题描述
我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 显示一个unresolved variable temp
在handleModalView()
. 但是,我的代码工作得很好。
编辑 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>)
}
推荐阅读
- python - 在 Django 中向模型条目添加步骤
- c# - WPF RichTextBox:查找当前在 RichTextBox 中可见的第一个块/段落
- windows - 在 Windows 中使用 shell 脚本附加 PATH 变量中的值
- python - 创建一个 Django 模型类,其字段值之一由其他模型的字段值计算,并且它必须存在于我的实际数据库表中
- python - 使用 Django rest 框架从 2 个不同的表中过滤
- r - 为分组箱线图排序数据集
- cypress - 在特定区域移动鼠标几次
- python - 有没有办法确保 Sqlite3 不会将其他整数 0 和 1 提交到布尔列
- python - 寻找最长簇的算法。(理想情况下是 Python,可能是 Matlab)
- jitsi - Jitsi Meet - 您已断开连接