0
我在我的代码中有一个语法错误,我不知道为什么。这是否与我使用的参考方式有关?为什么我的React组件类中有语法错误?
export default class ToggleMenu extends React.Component {
showRight: function() {
this.refs.right.show();
}
render() {
return (
<div>
<button onClick={this.showRight}>Show Left Menu!</button>
{/*
<Menu ref="right" alignment="right">
<MenuItem hash="1">First</MenuItem>
<MenuItem hash="2">Second</MenuItem>
<MenuItem hash="3">Third</MenuItem>
</Menu>
*/}
</div>
);
}
}
以下是错误:
./src/components/ToggleMenu/
ToggleMenu.js
Module build failed: SyntaxError: Unexpected token (13:14)showRight: function() { this.refs.right.show(); }
确定有意义感谢ü但至少为何IM歌厅下一个错误:未捕获的(以诺)类型错误:无法读取未定义 – Alex
@Alex的特性“绑定”你确定你把它在构造函数? – Li357
'出口默认类ToggleMenu扩展React.Component { 构造(道具){ 超(道具); this.showRight = this.showRight.bind(this); } 渲染(){ 回报(