首页 文章

在聚合物2.0中导入js库

提问于
浏览
0

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

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组件中导入它 .

相关问题