【发布时间】:2017-07-30 21:23:09
【问题描述】:
我需要在 Click 上触发一个事件,即 handleClick。它不适用于图像或任何按钮。
我也试过箭头函数,但也没有用。它也没有抛出任何错误。任何人都可以提出一些建议吗?
let Blips = React.createClass({
handleClick(){
if (this.props.user_name != null) {
sessionStorage.setItem('user_name', JSON.stringify(this.props.user_name))
sessionStorage.setItem('port_id', JSON.stringify(this.props.port_id))
sessionStorage.setItem('ship_image', JSON.stringify(this.props.ship_image))
sessionStorage.setItem('port_type', JSON.stringify(this.props.port_type))
browserHistory.push('/dockedship/')
}
},
render(){
if (this.props.user_name) {
return (
<li className="layer" data-depth={this.props.data_depth}>
<div className={this.props.css_location}>
<img className="glyphport" onClick={this.handleClick} src={this.props.port_type_image}/>
<img className="shipport" src={this.props.ship_image}/>
</div>
</li>
)
}
}
})
【问题讨论】:
-
添加完整的组件代码。
标签: javascript reactjs onclick