0

我有以下代码:

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">

  <base href="http://polygit.org/polymer+:master/components/">

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

  <link rel="import" href="paper-input/paper-input.html">
  <link rel="import" href="paper-dialog/paper-dialog.html">

  <title>JS Bin</title>
</head>
<body>

       <paper-input name="some"></paper-input>
          <paper-input name="some"></paper-input>

    <my-el></my-el>

    <dom-module id="my-el">
      <template>
        <style>
          display: block;
        </style>
         I AM HERE!

          <paper-input name="some"></paper-input>
          <paper-input name="some"></paper-input>

        <script>
          Polymer({
            is: "my-el",

            ready: function(){
              console.log("READY!?!");
            }
          })
        </script>
      </template>
    </dom-module>

    AND:

  </body>
</html>

哪个在这个 Jsbin 中:http://jsbin.com/qiyohaj/edit?html,console, output

非常简单的问题为什么地球上不会“x-el”显示,也不会运行ready()......?

4

1 回答 1

1

您在模板标签内拥有创建 web 组件的脚本部分,该元素永远不会被注册。

尝试用这个替换:

<dom-module id="my-el">
  <template>
    <style>
      display: block;
    </style>

    <paper-input name="some"></paper-input>
    <paper-input name="some"></paper-input>
  </template>
  <script>
    Polymer({
      is: "my-el",
      ready: function(){
        console.log("ready");
      }
    });
  </script>
</dom-module>
于 2016-08-30T09:08:04.967 回答