Introduction to how to use Polymer directly in html

You can use HTML's <script>tag to link to the Polymer library, and then use Polymer in HTML.

  1. Download the Polymer libraries and save them to your computer.

  2. 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>

  1. 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-elementPolymer element named containing an HTML tag with the context "Hello World!"

  1. 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

Guess you like

Origin blog.csdn.net/hdxx2022/article/details/132653241