首先,babel
的环境是没有问题的,因为我自己写的decorator
是有效的。
代码
import {autobind} from 'core-decorators';
...
<div className="tc common-op"
onClick={this.handleShow}>
<i className="icon iconfont"></i>
</div>,
...
@autobind
handleShow(){
console.warn(this);
this.props.handleTableCustomizeShow(true);
}
结果
也就是说,this为依然为null,难道是我的想法不对?@autobind
并不能解决React里事件中this的bind问题?
补充
在core-decorators.jsGitHub首页的@autobind
发现了note:
Note: there is a bug in react-hot-loader <= 1.3.0 (they fixed in 2.0.0-alpha-4) which prevents this from working as expected. Follow it here
但是我将react-hot-loader
升级到1.3.1
依然无效,看来可能是react-hot-loader
导致的,没办法,只好先暂停core-decorators.js的使用,后面再引入吧。
对此各位有其他的解决方案吗?
they fixed in 2.0.0-alpha-4