使用ES6的时候,用class创建组件,class中的方法并不会自动把this绑定到示例中,针对以上,有以下几种方法来进行绑定
1:使用.bind(this)
2:使用箭头函数 =>
3:将绑定方法写到constructor中
使用ES6的时候,用class创建组件,class中的方法并不会自动把this绑定到示例中,针对以上,有以下几种方法来进行绑定
1:使用.bind(this)
2:使用箭头函数 =>
3:将绑定方法写到constructor中
本文标题:ES6构建React应用时,this指向问题
本文链接:https://www.haomeiwen.com/subject/zflaettx.html
网友评论