在 Polymer 1.0 中,我可以使用以下方式声明属性:
properties: {
salary: {
type: Number,
value: 80
}
}
现在在 Polymer 2.0(创建一个类)中,我应该编写一个如下方法:
static get properties() {
return {
salary: {
type: Number,
value: 80
}
}
}
但现在 this.properties
为 null
。如何访问 properties
字段(而不是 properties
的值)?
最佳答案
this.properties
尝试访问实例字段(不包括静态字段)。由于 properties
是一个 static
字段,因此您必须使用 this.constructor.properties
或 XFoo.properties
>.
示例:
class XFoo extends Polymer.Element {
static get properties() { ... }
constructor() {
super();
// this.constructor === XFoo
console.log('this.constructor.properties', this.constructor.properties);
console.log('XFoo.properties', XFoo.properties);
}
}
关于javascript - 如何在 Google Polymer 2 中访问 'properties'?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43328333/