【问题标题】:Polymer hello-world component not renderingPolymer hello-world 组件未渲染
【发布时间】:2015-06-06 16:49:26
【问题描述】:

我正在关注 https://www.youtube.com/watch?v=wId1gMzriRE 的 Polymer 教程

我使用的是 Polymer 1.0(本教程是旧版本)。我已将 platform.js 更改为 webcomponents.js

现在我的index.html

<!doctype html>
<html>
  <head>
    <title>Polymer Trial</title>
    <script src="bower_components/webcomponentsjs/webcomponents.js"></script>
    <link rel="import" href="elements/hello-world.html">
  </head>
    <body>
        <h2>Test</h2>
        <hello-world></hello-world>
    </body>
</html>

我的元素文件 hello-world.html

<link rel="import" href="../bower_components/polymer/polymer.html">
<polymer-element name="hello-world" noscript>
    <template>
        <h1>Hello World!</h1>
    </template>
</polymer-element>

但是我在浏览器中得到的只是如下;没有“你好世界!”被渲染。

我错过了什么吗?我怎样才能找出问题出在哪里?

下面附上我的目录结构。

【问题讨论】:

    标签: polymer web-component


    【解决方案1】:

    较旧的教程不适用于 Polymer 1.0,因为有许多剧烈的变化。在新版本中,Hello World 如下所示:

    <dom-module id="hello-world">
      <template>
        <h1>Hello world!</h1>
      </template>
    </dom-module>
    
    <script>
      Polymer({
        is: 'hello-world'
      });
    </script>
    

    更多信息可以在 Polymer 文档中找到,https://www.polymer-project.org/1.0/docs/devguide/feature-overview.html

    【讨论】:

      猜你喜欢
      • 2019-07-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多