0

我想开始将我的 Polymer 1.0 应用程序移植到 Polymer 2.0(预览版)。

我用<template is="dom-bind">在我index.html的支持数据绑定。聚合物 2 也可以吗?我尝试<dom-bind>作为一个组件,但它没有工作。

4

1 回答 1

5

In Polymer 2.0, make sure to wrap the <template> inside <dom-bind> as described in the upgrade guide. It's also important to include polymer.html, which imports dom-bind.html (instead of only polymer-legacy.html).

Polymer 1.0:

<template is="dom-bind" id="app">
  ...
</template>

Polymer 2.0:

<dom-bind id="app">
  <template>
    ...
  </template>
</dom-bind>

const app = document.getElementById('app');

app.message = 'Hello world!';
app.counter = 0;

app._onClick = function() {
  this.counter++;
};
<head>
  <base href="https://polygit.org/polymer+2.2.0/components/">
  <script src="webcomponentsjs/webcomponents-lite.js"></script>
  <link rel="import" href="polymer/polymer.html">
</head>
<body>
  <dom-bind id="app">
    <template>
      <div>[[message]]</div>
      <div>[[counter]]</div>
      <button on-click="_onClick">Increment</button>
    </template>
  </dom-bind>
</body>

于 2017-01-03T06:52:33.877 回答