简体   繁体   English

在Polymer 2.0中导入js库

[英]Import js library in polymer 2.0

I'm facing an issue I want to know how can I import an external javascript "library/ file" to my polymer project. 我遇到一个问题,我想知道如何将外部javascript“库/文件”导入到我的Polymer项目中。 I want to use the htmlToPdf.js library in polymer. 我想在聚合物中使用htmlToPdf.js库。 but I can't call the functions on the htmlToPdf.js. 但我无法在htmlToPdf.js上调用函数。

If you are going to reuse the library in different components, then it is better to create an import component 如果要在不同的组件中重用该库,则最好创建一个导入组件

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM