javascript - 聚合物简单组件不工作 - 一切都已加载,但没有影子根,没有错误

标签 javascript html polymer-1.0

我正在尝试聚合物,但无法使其成为一个简单的组件。基于文档。我做了以下事情

添加了 webcomponents.js,导入了polymer.html,并创建了一个简单的 helloworld 组件,无需任何脚本。我可以看到 DEV 工具中加载的所有内容,但 helloworld 组件中未创建 shawdow 根。

聚合物版本为“聚合物”:“聚合物/聚合物#~1.0.5”

下面是 hello world 代码。

<polymer-element name="hello-world" noscript>
  <template>
    <h1>Hello World</h1>
  </template>
</polymer-element>

Webcomponentjs with 200

Polymer and helloworld components loaded

但是 helloworld 中没有影子根。 enter image description here

我在这里做错了什么。

最佳答案

您正在使用 Polymer v1.0,但您似乎没有按照该版本应有的方式声明您的元素。请参阅here :

<dom-module id="hello-world">
  <style>
    /* CSS rules for your element */
  </style>

  <template>
    <!-- local DOM for your element -->

    <h1>Hello world</h1>
  </template>

  <script>
    // element registration
    Polymer({
      is: "hello-world"
    });
  </script>
</dom-module>

关于javascript - 聚合物简单组件不工作 - 一切都已加载,但没有影子根,没有错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31140305/

相关文章:

javascript - 如何从 yeoman 输出不需要 grunt 服务即可查看的字典

javascript - 处理 openlayers mobile 标记的点击事件

jquery - 尝试在 css 中组合 div

html - 触发自动换行 : break-word in CSS

javascript - 仅当 Polymer 中表单验证成功时才发送 AJAX 请求

javascript - Polymer iron-ajax 间隔调用

javascript - 将选项动态添加到特定位置的选项组

javascript - vs2010 : trying to debug javascript using Chrome: this is not a valid location for a breakpoint

html - haml 文件中的 yaml 前端内容

dart - 纸张下拉菜单无法充分打开