以声明方式定义的 属性 值在 Polymer LitElement 中不起作用
Declaratively defined property values don't work in Polymer LitElement
声明定义的属性不会更新元素的 属性。
示例:
<my-elem myvalue="test"></my-elem>
static get properties() {
return {
myvalue: String //The value of this property doesn't update to "test"
}
reflectToAttribute 也不起作用。
更新已声明属性值的问题与 reflectToAttribute 相关,我相信。
如果您将以下代码添加到您的元素,则 属性 和属性之间的同步将起作用:
attributeChangedCallback(name, oldValue, newValue) {
if (name == "myvalue") this.myvalue = newValue; //change in attribute is updated to property
}
_render({ myvalue }) {
renderAttributes(this, {
'myvalue': myvalue //value of property is updated to attribute
});
return html`
<div>something...</div>
`;
}
声明定义的属性不会更新元素的 属性。
示例:
<my-elem myvalue="test"></my-elem>
static get properties() {
return {
myvalue: String //The value of this property doesn't update to "test"
}
reflectToAttribute 也不起作用。
更新已声明属性值的问题与 reflectToAttribute 相关,我相信。
如果您将以下代码添加到您的元素,则 属性 和属性之间的同步将起作用:
attributeChangedCallback(name, oldValue, newValue) {
if (name == "myvalue") this.myvalue = newValue; //change in attribute is updated to property
}
_render({ myvalue }) {
renderAttributes(this, {
'myvalue': myvalue //value of property is updated to attribute
});
return html`
<div>something...</div>
`;
}