简体   繁体   English

Polymer自定义元素样式在Firefox中不起作用(数据绑定问题?)

[英]Polymer custom element styling not working in Firefox (data binding issue?)

The following element works fine in Chrome, but not in firefox. 以下元素在Chrome中可以正常运行,但在Firefox中则不能。 What I'm expecting to see is my theme colours, which is defined in a separate place. 我希望看到的是我的主题色,它是在单独的位置定义的。

Now in firefox, the component itself renders, and it even creates the .swatch div, with the correct size of 40x40, as specified in the shadow dom styles. 现在,在firefox中,组件本身会进行渲染,甚至会创建如阴影dom样式中指定的.swatch div,其正确大小为40x40。 Unfortunately the background-color and border css rules are never applied. 不幸的是, background-colorborder css规则从未应用。

The console output in firefox and chrome is exactly as I would expect, with the correct colours, which tells me that the values does exist, but for some reason the data is not bound to the template in firefox? firefox和chrome中的控制台输出与我期望的完全一样,具有正确的颜色,这告诉我值确实存在,但是由于某些原因数据未绑定到firefox中的模板?

<polymer-element name="color-sample" attributes="color border">
    <template>
        <style>
            .swatch {
                width: 40px;
                height: 40px;
                margin-right: 0.5em;
                background-color: {{ swatchColor }};
                border: 1px solid {{ borderColor }};
            }
        </style>
        <div id="sample" layout horizontal center>
            <div class="swatch"></div>
            <content></content>
        </div>
    </template>
    <script>
        Polymer({
            color: "white",
            border: "lightGrey",
            ready: function() {
                this.swatchColor = CoreStyle.g.theme[this.color];
                this.borderColor = CoreStyle.g.theme[this.border];
                console.log(this.swatchColor);
                console.log(this.borderColor);
            }
        });
    </script>
</polymer-element>

I should also point out that if I use inline styles directly on the .swatch div, then the binding seems to work fine, but I'm specifically looking for a solution to bind to the css directly to keep the html clean. 我还应该指出,如果我直接在.swatch div上使用内联样式,则绑定似乎可以正常工作,但是我专门在寻找一种直接与CSS绑定以保持html干净的解决方案。

Seems I found the problem right after I posted. 似乎我在发布后立即发现了问题。 Data binding isn't fully supported in <style> under the shadow dom.[1] 影子dom下的<style>不完全支持数据绑定。[1]

[1] https://github.com/Polymer/polymer/issues/456 [1] https://github.com/Polymer/polymer/issues/456

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM