polymer 2.0导入js库

Import js library in polymer 2.0

我遇到了一个问题,我想知道如何将外部 javascript "library/ file" 导入到我的聚合物项目中。 我想在聚合物中使用 htmlToPdf.js 库。但我无法调用 htmlToPdf.js.

上的函数

您可以使用常规 <script> 标签将其导入到 Polymer 组件中。

如果你打算在不同的组件中重用这个库,那么最好创建一个导入组件

<!-- 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>