页面更改后,如何刷新/重新加载Polymer元素? [英] How can I refresh/reload Polymer element, when page changes?

查看:83
本文介绍了页面更改后,如何刷新/重新加载Polymer元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一些自定义元素.准备就绪时(由ready()触发),他们开始从API下载JSON数据,并显示给用户. 想要在单页应用程序中使用它们,并在可见时下载数据. 现在,因为我使用了ready()事件,所以它首先下载了所有页面的所有数据.

I created few custom elements. When they get ready(triggered by ready()), they start downloading JSON data from API, and show to the users. Want to use them in Single Page Application, and to download data when it becomes visible. Right now, it downloads all the data of all the pages first, because I used ready() event.

是否有可能在事件每次可见时触发一个事件?

Is it possible to fire an event every time they become visible?

推荐答案

我找到了解决方案.但是,这有点棘手. 首先,我添加了一个名为isEqual的函数.

I found a solution. But, it's a little bit tricky. First, I added a function called isEqual.

app.isEqual = function(x, y) {
  return x === y;
};

然后,使用dom-if.

<section data-route="groups">
  <template is="dom-if" if="{{isEqual(route, 'groups')}}" restamp="true">
    <tend-groups-joined></tend-groups-joined>
  </template>
</section>

因此,基本上,它会将当前路由与我传递的字符串参数进行比较(如果它与restamps相匹配).有点棘手,但是有效.

So, basically it compares the current route with a string parameter I pass, if it matches it restamps. A little bit tricky, but it worked.

这篇关于页面更改后,如何刷新/重新加载Polymer元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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