zoukankan      html  css  js  c++  java
  • polymer-quick tour of polymer

    注册一个元素

    <link rel="import"
          href="bower_components/polymer/polymer.html">
    //没有添加<dom-module> <script> Polymer({ is:'proto-element', ready:function(){ this.innerHTML='sfp'; } }) </script>

    增加本地元素:在<template>中

    <link rel="import"
          href="bower_components/polymer/polymer.html">
    
    <dom-module id="dom-element">
      <template>
        <p>I'm a DOM element. This is my local DOM!</p>
      </template>
    </dom-module>
    
    <script>
      Polymer({
        is: "dom-element",
      });
    </script>
    

    本地元素布局:在main中

    <link rel="import"
          href="bower_components/polymer/polymer.html">
    
    <dom-module id="picture-frame">
      <!-- scoped CSS for this element -->
      <style>
        div {
          display: inline-block;
          background-color: #ccc;
          border-radius: 8px;
          padding: 4px;
        }
      </style>
      <template>
        <div>
          <!-- any children are rendered here -->
          <content></content>
        </div>
      </template>
    </dom-module>
    
    <script>
      Polymer({
        is: "picture-frame",
      });
    </script>
    
    <!DOCTYPE html>
    <html>
      <head>
        <script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>
        <link rel="import" href="picture-frame.html">
      </head>
      <body>
        <picture-frame>
          <image src="images/p-logo.svg">
        </picture-frame>
      </body>
    </html>
    

    数据绑定:在Polymer()中定义数据,在<template>中显示

    <link rel="import"
          href="bower_components/polymer/polymer.html">
    
    <dom-module id="name-tag">
      <template>
        <!-- bind to the "owner" property -->
        This is <b>{{owner}}</b>'s name-tag element.
      </template>
    </dom-module>
    
    <script>
      Polymer({
        is: "name-tag",
        ready: function() {
          // set this element's owner property
          this.owner = "Daniel";
        }
      });
    </script> 

    声明properties:看起来跟数据绑定功能类似,其实是要序列化为attribute;声明attribute,用hostAttributes

    <link rel="import"
          href="bower_components/polymer/polymer.html">
    
    <dom-module id="configurable-name-tag">
      <template>
        <!-- bind to the "owner" property -->
        This is <b>{{owner}}</b>'s configurable-name-tag element.
      </template>
    </dom-module>
    
    <script>
      Polymer({
        is: "configurable-name-tag",
        properties: {
          // declare the owner property
          owner: {
            type: String,
            value: "Daniel"
          }
        }
      });
    </script>
    

    绑定properties:把定义的值传给属性

    <link rel="import"
          href="bower_components/polymer/polymer.html">
    <dom-module id='proto-element'>
      <style>
      div{
        100px;
        height:100px;
        background-color:olive;
      }
      </style>
      <template>
        <div>
          <p id='{{owner}}'>local dom</p>
          <content></content>
        </div>
      </template>
    </dom-module>
    <script>
    Polymer({
      is:'proto-element',
      properties:{
        owner:{
          type:String,
          value:'bind properties'
        }
      }
      
    })
    </script>
    

    绑定数据和ready:声明了一个属性owner,default value:'wj', ready 之后改为'sfp'

    <link rel="import"
          href="bower_components/polymer/polymer.html">
      <!-- 需要加一个id,value为proto-element -->
      <dom-module id='proto-element'>
        <template>
        //增加本地元素
          <p>this is a local dom</p>
          <p><strong>{{owner}}</strong> test data binding</p>
        </template>
      </dom-module>
      <script>
       Polymer({
         is: "proto-element",
         ready: function() {
          this.owner='sfp';
    
         },
         properties:{
          owner:{
            type:String,
            value:'wj'
          }
         }
       });
     </script>
    

      

     

      

  • 相关阅读:
    教务管理系统(node+express+mysql)
    poj 2485 Highways 超级大水题 kruscal
    HDU 1874 畅通工程续 + HDU 2544 最短路 最短路水题,floyd水
    HEX格式转BIN格式 MOT格式转BIN格式
    html的标签一共有多少个?
    同时存在n个线程(n>5),需要写入或者读取一个名为test.txt的文件
    poj 1258 AgriNet 水题三连发。。。又是kruscal
    招投标专家库
    poj 1789 kruscal水题
    仿Word自动套用格式,用CSS设置表格样式
  • 原文地址:https://www.cnblogs.com/wang-jing/p/4655877.html
Copyright © 2011-2022 走看看