你能得到一个计算样式(css mixin)作为JSON对象吗?

时间:2017-09-15 15:49:43

标签: javascript json polymer polymer-1.0

是否可以将计算出的样式值输出为JSON对象?

     ...
        ready: function() {
            // themeClass = css mixin --theme-typography 
            style = this.getComputedStyleValue( this.themeClass );

            console.log( style );
            // outputs:
            // font-size: 3.0000em; 
            //   line-height: 1.0000em; 
            //   margin-top: 0.5000em;
            //   margin-bottom: 0.0000em;
            //   font-weight: 400;
            //   font-family: Helvetica Neue, Helvetica, Arial, sans-serif;

        }

但理想情况应该是:

         {"font-size":"3.0000em;","line-height":"1.0000em;" etc.}

1 个答案:

答案 0 :(得分:0)

const style = this.getComputedStyleValue( this.themeClass );

console.log( JSON.stringify(style) );

这不是一个聚合物问题。