聚合物组分间数据绑定? [英] Polymer inter-component data binding?

查看:184
本文介绍了聚合物组分间数据绑定?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个登录组件,我想让我的应用程序中的其他组件登录状态可用。

I have a login component, and I'd like to make the login status available for other components in my application.

任何人都可以提供工作代码或示例?

Can anyone provide working code or examples?

我至少需要某种绑定或事件当登录状态发生变化时,可以相应地更新这些其他感兴趣的组件的UI。

I need some sort of binding or eventing at least, so that when the login status changes, the UI of these other interested components can be updated accordingly.

推荐答案

创建一个表示登录组件中的状态,并设置 notify:true
在登录组件和使用该状态的任何其他组件中使用数据绑定。

Create a property that represents the status in your login component and set notify: true. Use data-binding in your login component and any other components that use that status.

<login-component status="{{status}}"></login-component>
<other-component login="{{status}}"></other-component>

如果您使用聚合物模板之外的组件,请使用自动绑定, code>< template is =dom-bind> 。

If you use your components outside of a Polymer template, make use of autobind by wrapping them in a <template is="dom-bind">.

<template is="dom-bind">
    <login-component status="{{status}}"></login-component>
    <other-component login="{{status}}"></other-component>
</template>

这篇关于聚合物组分间数据绑定?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆