我遇到一个问题,我想知道如何将外部javascript“库/文件”导入到我的Polymer项目中。 我想在聚合物中使用htmlToPdf.js库。但我无法在htmlToPdf.js上调用这些函数。
答案 0 :(得分: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>
答案 1 :(得分:0)
您可以使用常规<script>
标签将其导入到Polymer组件中。