0

如果以下代码中的位置(firebaseURL) 包含用户值(如 auth.uid),则 firebase-collection数据将在登录时从 firebase-auth 刷新。我正在使用聚合物 1.6.0

<firebase-auth id="auth"
      location="[[firebaseURL]]"
      provider="{{provider}}" 
      params="{{params}}"
      user="{{user}}">
    </firebase-auth>

    <firebase-collection
      location="[[firebaseURL]]"
      data="{{messages}}">
    </firebase-collection>

这是因为从 firebase-auth 登录时,用户值会发生变化,并且会更改位置值,从而刷新来自 firebase-collection的数据。

但是,如果位置路径不包含用户值,则数据将不会在登录时显示,您必须刷新页面才能发生这种情况。

到目前为止,我发现解决此限制的唯一方法有点骇人听闻。

我必须修改 firebase-collection 的 html 代码,如下所示:

<firebase-collection
      location="[[_location(user)]]"
      data="{{messages}}">
    </firebase-collection>

像这样添加 _location() 函数,以强制 firebase-collection数据刷新并在登录时显示

  _location: function(u){
    // hacking - to trigger the update firebase-collection/document on-login / on-user-change
    return this.user ? this.firebaseURL : "";
  }

它有效,但对我来说看起来不正确。

有没有更好的方法,更聚合的方法?

谢谢

询问聚合物

4

1 回答 1

1

您可以使用 a有条件dom-if地标记:firebase-collectionuser

<template is="dom-if" if="[[user]]" restamp>
  <firebase-collection
    location="[[firebaseURL]]"
    data="{{messages}}">
  </firebase-collection>
<template>
于 2016-10-27T14:31:34.457 回答