首页 > 其他 > 详细

react es6中 this undefined

时间:2017-11-05 12:50:06      阅读:568      评论:0      收藏:0      [点我收藏+]

  在es6写法中,绑定事件的事件的回调是全局,顾返回的为undefined

  解决办法:

  1.使用es6箭头函数,箭头函数this默认指向上一层级的环境    如   <input onChange={()=>this.change()}  />

  2.使用bind绑定this  ,写在constructor里   如  this.change = this.change.bind(this);       

  

  

react es6中 this undefined

原文:http://www.cnblogs.com/rp-jscript/p/7787078.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!