You can use HTML's <script>
tag to link to the Polymer library, and then use Polymer in HTML.
-
Download the Polymer libraries and save them to your computer.
-
Link Polymer library files in HTML. For example, add the following line of code to your HTML file:
<head>
...
<script src="path/to/webcomponents-bundle.js"></script>
...
</head>
- Now you can use Polymer directly in your HTML files. For example, to create a Polymer element, use the following code:
<dom-module id="my-element">
<template>
<h1>Hello World!</h1>
</template>
<script>
Polymer({
is: 'my-element'
});
</script>
</dom-module>
This will create a my-element
Polymer element named containing an HTML tag with the context "Hello World!"
- Use your Polymer elements. For example, to use the Polymer element you created in your HTML file, use the following code:
<body>
<my-element></my-element>
</body>
This will display "Hello World!" in the browser.
This is the basic usage of Polymer in HTML files.
Reprinted from: Weidian Reading https://www.weidianyuedu.com