1

下面的代码在这个 jsbin中正常工作,但在这个 codepen这个 plunker这个 jsfiddle中都不能工作。

为什么不?我怎样才能让它在它没有的三个地方工作?

http://jsbin.com/yudavucola/1/edit?html,控制台,输出
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>

  <base href="http://polygit.org/polymer+:master/components/">
  <script src="webcomponentsjs/webcomponents-lite.js"></script>
  <link rel="import" href="polymer/polymer-element.html">
  <link rel="import" href="paper-dialog/paper-dialog.html">

  <!-- Ensure Web Animations polyfill is loaded since neon-animation 2.0 doesn't import it -->
  <link rel="import" href="neon-animation/web-animations.html">
  <link rel="import" href="neon-animation/animations/scale-up-animation.html">
  <link rel="import" href="neon-animation/animations/fade-out-animation.html">

</head>
<body>
  <dom-module id="my-el">
    <template>
      <button on-click="open">Open Dialog</button>
      <paper-dialog
        id="dialog"
        entry-animation="scale-up-animation"
        exit-animation="fade-out-animation"
        modal
       >
        <h2>Header</h2>
        <div>Dialog body</div>
      </paper-dialog>
    </template>
    <script>
      class MyEl extends Polymer.Element {
        static get is() { return 'my-el' }

    constructor() {
      super();
        }

        open() {
          console.log('opening...');
          this.$.dialog.open();
          console.log('opened!');
        }

      }

      customElements.define(MyEl.is, MyEl);
    </script>
  </dom-module>

  <my-el></my-el>
</body>
</html>
4

2 回答 2

1

由于除jsbin之外的所有其他站点都使用HTTPie的安全版本HTTPS,因此从源获取内容的请求http://polygit.org/polymer+:master/components/被阻止。因此,使用安全连接,它将在所有其他站点中工作。

您可以查看控制台以获取更多信息。

于 2017-09-05T02:03:00.323 回答
0

<base>将标签的href属性从更改http://polygit.org/...//polygit.org/...。这使导入正常化以在httphttps环境中工作。

以下是所有存储库中的工作示例:JsBinCodepenPlunkerJsFiddle

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

  <base href="//polygit.org/polymer+:master/components/">
  <script src="webcomponentsjs/webcomponents-lite.js"></script>
  <link rel="import" href="polymer/polymer-element.html">
  <link rel="import" href="paper-dialog/paper-dialog.html">

  <!-- Ensure Web Animations polyfill is loaded since neon-animation 2.0 doesn't import it -->
  <link rel="import" href="neon-animation/web-animations.html">
  <link rel="import" href="neon-animation/animations/scale-up-animation.html">
  <link rel="import" href="neon-animation/animations/fade-out-animation.html">

</head>
<body>
  <dom-module id="my-el">
    <template>
      <button on-click="open">Open Dialog</button>
      <paper-dialog
        id="dialog"
        entry-animation="scale-up-animation"
        exit-animation="fade-out-animation"
        modal
       >
        <h2>Header</h2>
        <div>Dialog body</div>
      </paper-dialog>
    </template>
    <script>
      class MyEl extends Polymer.Element {
        static get is() { return 'my-el' }

    constructor() {
      super();
        }

        open() {
          console.log('opening...');
          this.$.dialog.open();
          console.log('opened!');
        }

      }

      customElements.define(MyEl.is, MyEl);
    </script>
  </dom-module>

  <my-el></my-el>
</body>
</html>

编辑

请注意,对于特定版本的 Polymer,您可以使用

<base href="//polygit.org/polymer2.0+:master/components/">

或者

<base href="//polygit.org/polymer1.0+:master/components/">

等等

于 2017-09-05T07:55:51.287 回答