layout: default
type: guide
shortname: Docs
title: Feature overview
subtitle: Developer guide
The Polymer library provides a set of features for creating custom elements. These features are designed to make it easier and faster to make custom elements that work like standard DOM elements. Similar to standard DOM elements, Polymer elements can be:
Polymer庫為您提供了一套功能來創(chuàng)建自定義標簽骂蓖。這些功能設(shè)計能夠簡單征讲、迅速地讓自定義標簽象標準DOM標簽一樣使用。類似標準DOM標簽,Polymer標簽?zāi)軌颍?/p>
- Instantiated using a constructor or
document.createElement
. - Configured using attributes or properties.
- Populated with internal DOM inside each instance.
- Responsive to property and attribute changes (for example, by populating data into the DOM, or firing an event).
- Styled with internal defaults or externally.
- Responsive to methods that manipulate its internal state.
- 使用構(gòu)造函數(shù)或者
document.createElement
實例化锥债; - 配置使用特征或?qū)傩裕?/li>
- 位于每個實例的內(nèi)部DOM;
- 響應(yīng)屬性和特征的變化(例如,填充數(shù)據(jù)到DOM锁荔,或者觸發(fā)事件)瞎领;
- 內(nèi)部默認樣式或外部樣式;
- 響應(yīng)方法操作內(nèi)部狀態(tài)勇劣;
A basic {{site.project_title}} element definition looks like this:
基本{{site.project_title}}標簽定義看上去像這樣:
<dom-module id="element-name">
<template>
<style>
/* CSS rules for your element 你標簽的CSS規(guī)則 */
</style>
<!-- local DOM for your element 你標簽的局部DOM-->
<div>{%raw%}{{greeting}}{%endraw%}</div> <!-- data bindings in local DOM 在局部DOM內(nèi)的數(shù)據(jù)綁定-->
</template>
<script>
// element registration 注冊標簽
Polymer({
is: "element-name",
// add properties and methods on the element's prototype
// 在標簽原型上添加屬性和方法
properties: {
// declare properties for the element's public API
// 為標簽的公共API聲明屬性
greeting: {
type: String,
value: "Hello!"
}
}
});
</script>
</dom-module>
This guide divides the features into the following groups:
這個指南將劃分為以下幾組功能:
- Registration and lifecycle. Registering an element associates a class (prototype) with a custom element name. The element provides callbacks to manage its lifecycle. Use behaviors to share code.
- 注冊和生命周期靖避。通過一個自定義標簽名注冊一個標簽并關(guān)聯(lián)一個Class(原型)。標簽提供回調(diào)函數(shù)管理它的生命周期比默。通過行為共享代碼幻捏。
- Declared properties. Declared properties can be configured from markup using attributes. Declared properties can optionally support change observers, two-way data binding, and reflection to attributes.You can also declare computed properties and read-only properties.
- 聲明屬性。屬性聲明可以從標記上使用特征來配置命咐。屬性聲明支持隨意改變觀測者篡九,雙向數(shù)據(jù)綁定,和反射到特征醋奠。你還可以聲明計算屬性和只讀屬性榛臼。
- Local DOM. Local DOM is the DOM created and managed by the element.
- 局部DOM。局部DOM是通過標簽創(chuàng)建和管理的DOM
-
Events. Attaching event listeners to the host object
and local DOM children. Event retargeting. - 事件窜司。附加事件監(jiān)聽器到主機對象和局部DOM沛善。事件重定向。
- Data binding. Property bindings. Binding to attributes.
- 事件綁定例证。屬性綁定路呜。綁定到特征。
- Behaviors. Behaviors are reusable modules of code that can be mixed into {{site.project_title}} elements.
- 行為。行為是能夠混合到{{site.project_title}}標簽里的可重用的代碼模塊胀葱。
- Utility functions. Helper methods for common tasks.
- 公用函數(shù)漠秋。為共同任務(wù)的幫助方法。
- Experimental features and elements. Experimental template and styling features. Feature layering.
- 實驗功能和標簽抵屿。實驗?zāi)0搴蜆邮焦δ芮旖酢9δ軐印?/li>
If you're migrating an existing 0.5 element to the new APIs, see the Migration guide for advice.
如果你從 0.5版遷移到新APIs,參看遷移指南
If you're upgrading from the 0.8 release, see the Release notes.
如果你從0.8版升級轧葛,參考版本說明搂抒。