【发布时间】:2015-11-14 13:59:15
【问题描述】:
我很难理解polymer element lifecycles。
假设我有一个具有单个属性 fooBar 的自定义元素。并假设我将fooBar 设置为属性上的一个属性,如下所示。
<custom-element foo-bar="text"></custom-element>
现在假设我想在元素生命周期创建期间以编程方式使用fooBar 作为属性。就像这样。
Polymer({
is: "custom-element",
properties: {
fooBar: {type: String}
},
ready: function(){
console.log(this.fooBar)
},
attached: function(){
console.log(this.fooBar)
}
})
据我所知,直到调用ready 和attached 之后,才从DOM 属性fooBar 加载元素属性fooBar。这是真的even when I call async from inside the ready and attached callbacks。
谁能解释 (1) 元素属性在生命周期的哪个位置从 DOM 属性导入,以及 (2) 如何以编程方式访问这些属性以对元素进行一些设置工作?
【问题讨论】:
标签: javascript polymer polymer-1.0 web-component google-web-component