Polymer 如何使用LitElement组件正确处理道具更改?

Polymer 如何使用LitElement组件正确处理道具更改?,polymer,web-component,lit-element,Polymer,Web Component,Lit Element,我的设想: 我有一个用LitElement创建的web组件,它有一个object属性。 为了初始化它,我正在等待创建元素: document.addEventListener(“DOMContentLoaded”,()=>{ const instance=document.querySelector(“myInstance”); instance.config={ 数据:[ {姓:“约翰”,姓:“多伊”,年龄:32}, {姓:“简”,姓:“英格兰银行”,年龄:30}, ] }; }); 假设

我的设想: 我有一个用LitElement创建的web组件,它有一个object属性。 为了初始化它,我正在等待创建元素:


document.addEventListener(“DOMContentLoaded”,()=>{
const instance=document.querySelector(“myInstance”);
instance.config={
数据:[
{姓:“约翰”,姓:“多伊”,年龄:32},
{姓:“简”,姓:“英格兰银行”,年龄:30},
]
};
});
假设我将不时更改此
数据
道具。
我想检查
数据更改后的值,然后决定下一步应该做什么。为此,以下是我的web组件的代码:

@customElement(“我的组件”)
导出类MyComponent扩展了LitElement{
@属性({type:Object})数据:Object;
受保护的已更新(_changedProperties:Map):无效{
console.log(_changedProperties);
}
render(){
返回html`
布拉布拉
`;
}
}
问题是
\u changedProperties
地图有
数据
,但它仍然未定义。
我在这里遗漏了什么?

changedProperties是所有已更改的属性名称的映射。。。e、 g.您可以使用它检查更改的内容-如果您想访问实际值,可以直接使用该属性

看起来像这样

if (_changedProperties.has('myProperty')) {
  // react to a myProperty change
  console.log('The new value of myProperty is', this.myProperty);
}

changedProperties是所有已更改的属性名称的映射。。。e、 g.您可以使用它检查更改的内容-如果您想访问实际值,可以直接使用该属性

看起来像这样

if (_changedProperties.has('myProperty')) {
  // react to a myProperty change
  console.log('The new value of myProperty is', this.myProperty);
}