簡體   English   中英

在Polymer 2.0中導入js庫

[英]Import js library in polymer 2.0

我遇到一個問題,我想知道如何將外部javascript“庫/文件”導入到我的Polymer項目中。 我想在聚合物中使用htmlToPdf.js庫。 但我無法在htmlToPdf.js上調用函數。

如果要在不同的組件中重用該庫,則最好創建一個導入組件

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