中等React
0 1

React 中除了在构造函数中绑定this,还有其他绑定this的方式么?

【概念释义】

类组件方法作事件回调时 this 默认不指向实例。除 constructor 里 bind 外,还有:类字段箭头函数 handle = () => {}包装箭头 onClick={() => this.handle()}bind 在 JSX onClick={this.handle.bind(this)}(不推荐每次 render 新建)。函数组件无 this 问题。

【基础使用】

jsx
class Form extends React.Component {
  constructor(props) {

登录查看完整 1197

回答讨论

暂无讨论,登录后可抢先发言

本题库更多题目(50)