我正面临一个问题,我想知道如何将外部javascript“库/文件”导入我的聚合物项目 . 我想在聚合物中使用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组件中导入它 .
<script>
2 回答
如果要在不同组件中重用库,则最好创建导入组件
您可以使用常规
<script>
标记在Polymer组件中导入它 .