gpt4 book ai didi

javascript - polymer 组件间数据绑定(bind)?

转载 作者:搜寻专家 更新时间:2023-11-01 04:15:36 24 4
gpt4 key购买 nike

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

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

我至少需要某种绑定(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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com