为什么这个AureliaJS-ReactJS example中有一个名为bind()的函数?这是 Aurelia 或 React 的回调方法吗?它将在应用程序生命周期中调用?
@noView()
@inject(Element)
export class Hello {
@bindable foo = "!";
constructor(element) {
this.element = element;
}
render() {
ReactDom.render(<HelloTest foo={this.foo} />, this.element);
}
bind() {
this.render();
}
fooChanged() {
this.render();
}
}
最佳答案
bind
是一个 Aurelia view life-cycle hook :
bind(bindingContext:any)
- Invoked when the databinding engine binds the view. The binding context is the instance that the view is databound to.
在示例中,因为 Hello
扩展是用 @noView()
修饰的(因此 Aurelia 不会尝试为其查找模板), bind
hooked 用于将 React 组件渲染到绑定(bind)的 this.element
。
关于reactjs - 为什么这个aureliaJS-reactJS示例中有一个名为bind()的函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32024684/