【问题标题】:Polymer 1.0 <template> tag not workingPolymer 1.0 <template> 标签不起作用
【发布时间】:2015-08-09 19:08:31
【问题描述】:

我从docs 中提取了最基本的示例,似乎&lt;template&gt; 标记不起作用。安装在文档中的 &lt;register-me&gt; 标记内没有呈现任何内容:

预期:“来自本地 DOM 的问候”

    <!DOCTYPE html>
    <html>
    <head>
      <title>Polymer 1.0.6 test</title>
      <script src="https://rawgit.com/webcomponents/webcomponentsjs/v0.7.10/webcomponents-lite.min.js"></script>
      <link rel="import" href="https://rawgit.com/Polymer/polymer/v1.0.6/polymer-mini.html">
    </head>
    <body>
      
    <dom-module id="register-me">
      <template>
        <div>Hello from my local DOM</div>
      </template>
      <script>
        Polymer({is: "register-me"});
      </script>
    </dom-module>
      
    <register-me></register-me>

    </body>
    </html>

直播:http://jsbin.com/qijegu/edit?html,output

【问题讨论】:

    标签: polymer polymer-1.0


    【解决方案1】:

    您使用的是 Polymer Micro,它不包括模板冲压。但是,它包含在 Polymer Mini 中 (docs)。

    编辑

    如果你想在你的主文档中定义元素,你需要监听 HTMLImports.whenReady 事件。否则,它将无法在某些浏览器中运行。这是解释here

    HTMLImports.whenReady(function () {
         Polymer({is: "register-me"});
    });
    

    【讨论】:

    • 切换到polymer-mini,它适用于Chrome 44,但不适用于Firefox 40。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-21
    • 2015-09-24
    相关资源
    最近更新 更多