在聚合物2.0中导入js库

问题描述 投票:0回答:2

我正面临一个问题,我想知道如何将外部javascript“库/文件”导入我的聚合物项目。我想在聚合物中使用htmlToPdf.js库。但我无法调用htmlToPdf.js上的函数。

javascript polymer polymer-2.x polymer-starter-kit
2个回答
1
投票

如果要在不同组件中重用库,则最好创建导入组件

<!-- htmlToPdf-import.html -->
<script src="../htmlToPdf/htmlToPdf.js" charset="utf-8"></script>

<!-- my-component.html -->

<link rel="import" href="./htmlToPdf-import.html">

<dom-module id="my-component">
  <template>
  </template>

  <script>
    class MyComponent extends Polymer.Element {
      static get is() {
        return 'my-component';
      }
    }

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

0
投票

您可以使用常规<script>标记在Polymer组件中导入它。

© www.soinside.com 2019 - 2024. All rights reserved.