问题描述
我正在从0.5迁移到1.0.
I'm doing migration from 0.5 to 1.0.
在阅读的同时,我注意到使用hostAttributes
和properties
声明属性的两种不同方式.
While reading, I notice 2 different way on declaring attributes, using hostAttributes
and properties
.
这2个有什么区别?
推荐答案
主机属性是与元素的相应Javascript属性(在properties
中声明的)不匹配的属性.这包括class
,tabindex
,data-*
属性,aria-roles等属性.要在创建时声明它们,必须在hostAttributes
对象中进行设置.如果要将值绑定到它们中,则必须使用$=
(它调用Element.setAttribute
)而不是=
.
Host attributes are attributes that do not match to an element's corresponding Javascript property (which you declare in properties
). This includes attributes like class
, tabindex
, data-*
attributes, aria-roles, etc. To declare them during create-time, you must set them in the hostAttributes
object. If you are going to bind values into them, you must use $=
(which calls Element.setAttribute
) rather than =
.
来源:
- https://www.polymer- project.org/1.0/docs/devguide/registering-elements.html#host-属性
- https://www.polymer- project.org/1.0/docs/devguide/data-binding.html#attribute-binding
- https://www.polymer-project.org/1.0/docs/devguide/registering-elements.html#host-attributes
- https://www.polymer-project.org/1.0/docs/devguide/data-binding.html#attribute-binding
这篇关于聚合物中的hostAttributes和properties有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!