【问题标题】:Polymer web-component inline script not loaded in firefox聚合物 web 组件内联脚本未在 firefox 中加载
【发布时间】:2015-10-23 22:08:38
【问题描述】:

当我的聚合物 Web 组件在 Firefox 中加载时,我遇到了一个奇怪的行为。

问题是,后面的javascript

<content></content> 

没有在 Firefox 中加载,但在 chrome 中可以正常工作。

我使用聚合物版本 1.0

我的元素如下所示:

<link rel="import" href="../../../../bower_components/polymer/polymer.html">

<dom-module id="my-element">

  <style>
     ...style content
  </style>

  <template>
    <svg  ...my svg></svg>

    <content></content>


    <script> --> This script is not loaded in firefox.
       ...script content
    </script>

  </template>
</dom-module>

<script>

  Polymer({
    is: 'my-element'

    ... etc ...

  });

</script>

我们将不胜感激。

【问题讨论】:

  • 快速检查,您使用的是 webcomponents 的 polyfill 对吗?

标签: javascript firefox polymer web-component


【解决方案1】:

我遇到了同样的问题,但重新阅读了我找到的文档the solution

在加载 Polymer Script 之前,您需要等待 DOM 准备好,如下所示:

<dom-module id="my-element">
    <template>
        <svg ...></svg>

        <content></content>

     </template>
     <script>
         HTMLImports.whenReady(function () {
              Polymer({
                  is: 'my-element'
                  // (...)
              });
         });
    </script>
</dom-module>

<my-element></my-element>

【讨论】:

    【解决方案2】:

    您可以使用组件的生命周期方法之一(例如“附加”)来执行相同操作,而不是在模板中包含脚本标记。

    【讨论】:

    • 是的,这就是我所做的,我不得不以其他方式重写我的代码,但它现在可以工作了。但这并不能解释为什么会出现这个问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-08-13
    • 1970-01-01
    • 2014-09-19
    • 1970-01-01
    • 2014-09-30
    • 1970-01-01
    • 2014-12-18
    相关资源
    最近更新 更多