我正在深入研究 Polymer 1.0 元素,我对计算的属性有点好奇。
例如,在paper-drawer-panel.html中,
<dom-module id="paper-drawer-panel" …>
…
<div id="main" style$="[[_computeDrawerStyle(drawerWidth)]]">
…
</div>
…
</dom-module>
<script>
Polymer({
is: 'paper-drawer-panel',
…
_computeDrawerStyle: function(drawerWidth) {
return 'width:' + drawerWidth + ';';
},
…
</script>
drawerWidth
是 的一个属性paper-drawer-panel
,那么为什么将它显式包含在计算属性的参数中如此重要?
是
[[_computeDrawerStyle()]]
…
_computeDrawerStyle: function () {
return 'width:' + this.drawerWidth + ';';
}
这是不好的做法吗?