当存在来自 redux 的属性时,如何在 litElement 中使用 @属性 装饰器语法

How use @property decorator syntax in litElement when there are properties from the redux

当我们使用构造函数赋值@属性时,decoratort看起来像

@property ({type: String}) name = 'Luis';

并且工作正常 但是当我使用 redux 并因此使用 _stateChanged 时,我尝试使用

@property ({type: String}) name

没有名称值,因为值在 _stateChanged 函数中定义 那么如何让它一起工作

我发现了很多这样使用装饰器的例子

export class MyElement extends LitElement {
 

     @property({type: String}) propertyName = "name"

它可以代替构造函数定义,但就我而言,我有 _stateChanged function 当我写这样的代码时,它不能正常工作,请举例说明这个装饰器与 _stateChanged(redux)

的用法

您可以继续使用常规 @property,无论该值是从外部还是内部设置的,例如还原。类型信息仅用于让 LitElement 根据属性填充 属性 值,但只要设置了具有相同名称的属性,它就会被忽略。

您还可以使用 @internalProperty,它不需要您定义类型,也不会将 属性 反映到具有相同名称的属性。