簡體   English   中英

鉻上的聚合物附着生命周期與Firefox上不同

[英]Polymer attached lifecycle on chrome is different than on firefox

語境

我在頁面中有一個組件 目前,我正在從組件觸發事件,並從頁面附加事件添加eventListener。

問題

當使用firefox時,我沒問題, 頁面組件之前加載,但是在chrome上,我的情況相反, 組件page之前加載。 這導致我在組件觸發事件之后添加一個eventListener。

我可以在應用程序后強制加載組件嗎?

演示版

適用於Firefox,但不適用於chrome:

應用程式

<link rel="import" href="x-el.html" async>

<dom-module id="x-app">
  <template>
    <x-el id="el"></x-el>
    <div hidden$="[[!detail]]">Event Detail: [[detail]]</div>
  </template>
  <script>
    Polymer({
      is: 'x-app',

      attached: function(){
        this.$.el.addEventListener('foo', () => {
          this.set('detail', 'hello')
        })
      }
    });
  </script>
</dom-module>

元件

<dom-module id="x-el">
  <template>
    <div>Hello from <code>x-el</code></div>
  </template>
  <script>
    Polymer({
      is: 'x-el',
      attached: function() {
        this.fire('foo', 'hello');
      }
    });
  </script>
</dom-module>

您可以使用page元素的listeners對象設置事件監聽器

// template
<x-el id="el"></x-el>

// script
Polymer({
  is: 'x-page',
  listeners: { 'el.foo': 'onFoo' },
  onFoo: function(e) {...}
});

矮人

或使用帶注釋的事件偵聽器:

// template
<x-el on-foo="onFoo"></x-el>

// script
Polymer({
  is: 'x-page',
  onFoo: function(e) {...}
});

矮人

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM