reactjs - 为什么这个aureliaJS-reactJS示例中有一个名为bind()的函数?

标签 reactjs bind aurelia

为什么这个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/

相关文章:

c++ - 如何使用 std::bind() 调用基类版本的虚函数?

javascript - 如何针对不同客户组织、构建和交付 NodeJS 应用程序

javascript - 在 create-react-library 库中配置相对于根目录的导入

ReactJS/Next.js : CRA Proxy Does Not Work With Next. js(尝试将 API 请求路由到 Express 服务器)

css - 无法使用样式化组件和 Next.js 导入 Google 字体

javascript - Aurelia 中 fetch() 的错误处理

typescript - Webpack 排除规范文件

javascript - 在 next.js 中将 Prop 作为类名传递

Javascript:函数绑定(bind)不适用于调用者

使用 .bind 进行 jQuery 表单验证 ('submit' )