我正在从 0.5 迁移到 1.0。
在阅读时,我注意到声明属性的两种不同方式,使用hostAttributes
和properties
。
那 2 有什么区别?
我正在从 0.5 迁移到 1.0。
在阅读时,我注意到声明属性的两种不同方式,使用hostAttributes
和properties
。
那 2 有什么区别?
主机属性是与元素的相应 Javascript 属性(您在 中声明的属性)不匹配的属性properties
。这包括像class
, tabindex
,data-*
属性, aria-roles 等属性。要在创建时声明它们,您必须在hostAttributes
对象中设置它们。如果要将值绑定到它们中,则必须使用$=
(调用Element.setAttribute
)而不是=
.
资料来源:
如果自定义元素需要在创建时为其设置 HTML 属性,则可以在原型的 hostAttributes 属性中声明属性,其中键是属性名称,值是要分配的值。
但是现在由于 listeners 和 hostAttributes 已从元素元数据中删除
我们可以使用 _ensureAttribute 作为替代来定义这些属性
前任:-
this._ensureAttribute('tabindex', 0); 您可以在 ready 中声明所有此类属性