dom-bind与Polymer 2.0-preview

Joc*_*ner 0 binding polymer polymer-2.x

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

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

ton*_*y19 5

在Polymer 2.0中,确保按照升级指南中的说明<template>内部包裹起来.包括哪些进口(而不是仅进口)也很重要.<dom-bind>polymer.htmldom-bind.htmlpolymer-legacy.html

聚合物1.0:

<template is="dom-bind" id="app">
  ...
</template>
Run Code Online (Sandbox Code Playgroud)

聚合物2.0:

<dom-bind id="app">
  <template>
    ...
  </template>
</dom-bind>
Run Code Online (Sandbox Code Playgroud)

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

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

app._onClick = function() {
  this.counter++;
};
Run Code Online (Sandbox Code Playgroud)
<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>
Run Code Online (Sandbox Code Playgroud)