1

我试图理解core-style。我注意到,到目前为止,在我看到的所有示例中,只有 Button 等元素在 a 中被引用core-style- 没有类引用(例如.blue)。我试图在其中放置一个类引用,core-style但它没有呈现。请看下面的例子

.html

    <link href='../../../../packages/polymer/polymer.html' rel='import' >
    <link href='../../../../packages/core_elements/core_style.html' rel='import' >

    <polymer-element name='blue-theme'>

      <template>
        <core-style id='blue-theme'>
            :host {
                background-color: red;

                .lb-container1 {
                   background-color: {{lb50}};
                   padding-top: 5px;
                 padding-bottom: 5px;
                 width: {{width}}
                }   
          }

        </core-style>
      </template>

      <script type='application/dart' src='blue_theme.dart'></script>
    </polymer-element>

。镖

import 'package:polymer/polymer.dart';

import 'package:epimss_shared/epimss_shared_client.dart' hide DataEvent;

@CustomTag( 'blue-theme' )
class BlueTheme extends PolymerElement
{
  String topic = '';

  @observable String lb50 = LightBlue['50'];
  @observable String lb100 = LightBlue['100'];
  @observable String lb200 = LightBlue['200'];

  BlueTheme.created() : super.created();

  @published
  String get width => readValue( #width );
  set width(String value) => writeValue( #width, value );

  @override
  void attached()
  {
     super.attached();
     topic = this.dataset['topic'];

  }
}

上面的代码不渲染。

谢谢

4

1 回答 1

0

您只创建了一个<core-style>生产者(提供可重复使用的样式)。你还需要一个<core-style>消费者。

<core-style ref="blue-theme"></core-style>

我自己没有使用过它,但我认为只需添加这一行就可以解决问题。您可以在不同的元素中拥有生产者和消费者。那是元素的重点。定义一次样式并通过引用重复使用它。

到目前为止,本教程看起来不错https://pascalprecht.github.io/2014/08/01/sharing-styles-across-web-components-with-polymer-and-core-style/

于 2015-01-29T11:01:57.533 回答