我有一个登录组件,我想让登录状态对我的应用程序中的其他组件可用。
任何人都可以提供工作代码或示例吗?
我至少需要某种绑定(bind)或事件,以便当登录状态发生变化时,这些其他感兴趣的组件的 UI 可以相应地更新。
最佳答案
在您的登录组件中创建一个表示状态的属性并设置 notify: true
.
在您的登录组件和使用该状态的任何其他组件中使用数据绑定(bind)。
<login-component status="{{status}}"></login-component>
<other-component login="{{status}}"></other-component>
如果您在 Polymer 模板之外使用您的组件,请通过将它们包装在 <template is="dom-bind">
中来使用自动绑定(bind).
<template is="dom-bind">
<login-component status="{{status}}"></login-component>
<other-component login="{{status}}"></other-component>
</template>
关于javascript - polymer 组件间数据绑定(bind)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31582026/