简体   繁体   English

将Polymer.updateStyles与@apply mixin一起使用

[英]Using Polymer.updateStyles with @apply mixin

I have a dynamically Polymer 2.0 application, but it doesn't seem to work with @apply . 我有一个动态的Polymer 2.0应用程序,但似乎不适用于@apply

I have CSS variables and mixins: 我有CSS变量和mixins:

<custom-style>
    <style>
        html {
            --content-background-colour: #fff;
            --content-foreground-colour: var(--paper-grey-700);

            --content-mixin: {
                background-color: var(--content-background-colour);
                color: var(--content-foreground-colour);
            }
        }

        .content-one {
            background-color: var(--content-background-colour);
            color: var(--content-foreground-colour);
        }

        .content-two {
            @apply --content-mixin
        }
    </style>
</custom-style>

Then I have themes that users can select and apply: 然后,我有了用户可以选择和应用的主题:

const theme = {
    "--content-background-colour": "var(--paper-grey-800)",
    "--content-foreground-colour": "var(--paper-grey-100)"
};

Polymer.updateStyles(theme);

The problem is that only the direct variables update, those set with @apply don't. 问题在于只有直接变量会更新,而使用@apply设置的变量不会更新。 class="content-one" works, class class="content-two" fails. class="content-one"有效,class class="content-two"失败。

What am I doing wrong and how do I dynamically change the styles of mixins? 我在做什么错,如何动态更改mixins的样式?

Polymer still seems to be using same polyfill for variables and mixins that they were using in 1.x, which means dynamic style updating should only be limited to variables and should not work for mixins. Polymer似乎仍然在变量和混合中使用与1.x中相同的polyfill,这意味着动态样式更新应仅限于变量,而不适用于混合。

One way you can achieve dynamic styling is by adding and removing classes. 实现动态样式的一种方法是添加和删除类。

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

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