所以我正在努力学习反应,并.bind(this)
在构造函数中与理解混淆了一点.但是我想我现在明白了,只是想知道为什么我会在onClick中使用它与箭头函数.见下面的代码:
绑定方法确保eventClick函数中的'this'引用该类
Class Click extends react.Component {
constructor(props) {
super(props)
this.clickEvent = this.clickEvent.bind(this);
}
render = () => (
<button onClick={this.clickEvent}>Click Me</button>
)
clickEvent() {console.log(this)} // 'this' refers to the class
}
Run Code Online (Sandbox Code Playgroud)
但是这个方法也引用了这个类.是否有任何赞成/反对使用一个与另一个?
Class Click extends react.Component {
render = () => (
<button onClick={() => {this.clickEvent()}}>Click Me</button>
)
clickEvent() {console.log(this)} // 'this' refers to the class
}
Run Code Online (Sandbox Code Playgroud) 在页面加载时,对于第一秒,第一张幻灯片仅占用屏幕的一半,然后进行自我修正.它会导致令人不快/快速的负载体验.如果我通过检查监视元素代码,我可以看到内联宽度在页面加载后第二次更新.有什么建议?
我有一个内容类型,事件,有一个部分"StartDate",我需要在摘要视图中显示两次.在placement.info中是否可以在"this"区域和"那个"区域中渲染零件?