在聚合物中印刷当年

时间:2017-10-15 15:54:45

标签: polymer

我对聚合物有点新意,但我想知道是否有办法打印本年度并将其放在我的页脚中,这样我就可以随时获得最新的版权声明。

我尝试过Javascript但是它不起作用,任何帮助都会很棒!感谢。

1 个答案:

答案 0 :(得分:0)

create a Polymer element contains a property初始化为当前年份(由Date#getFullYear()确定):



HTMLImports.whenReady(() => {
  class XCopyright extends Polymer.Element {
    static get is() { return 'x-copyright'; }

    static get properties() {
      return {
        year: {
          type: String,
          value: () => new Date().getFullYear()
        }
      };
    }
  }
  customElements.define(XCopyright.is, XCopyright);
});

main {
  height: calc(100vh - 30px);
}
footer {
  display: flex;
  height: 30px;
  justify-content: center;
}

<head>
  <base href="https://polygit.org/polymer+v2.1.1/components/">
  <script src="webcomponentsjs/webcomponents-lite.js"></script>
  <link rel="import" href="polymer/polymer.html">
</head>
<body>
  <main></main>
  <footer>
    <x-copyright></x-copyright>
  </footer>

  <dom-module id="x-copyright">
    <template>
      <span>&copy; {{year}}</span>
    </template>
  </dom-module>
</body>
&#13;
&#13;
&#13;

demo