Polymer支持<style is="custom-style">
,允许您定义仅适用于元素的样式,例如影子DOM。
Polymer还支持<dom-module id="shared-styles">
,它允许您打包一组可以导入到元素定义中的样式声明。
因此,两者的关键似乎是允许您设计聚合物元素的样式。你为什么要用另一个呢?看起来,用例大致重叠。
其他混淆:shared-styles
可以导入custom-style
。你为什么要这样做?为什么不呢?
答案 0 :(得分:15)
<dom-module id="my-shared-styles">
声明可重复使用的样式模块,您可以将其导入元素或<style is="custom-style">
标记。
在自定义元素中使用
<dom-module id="my-element>
<template>
<style include="my-shared-styles"></style>
...
</template>
</dom-module>
或在自定义元素外的<style>
标记中(例如在<head>
中)
<head>
<style is="custom-style" include="my-shared-styles"></style>
</head>
仅当您要在不在<style is="custom-style">
内的样式元素中使用Polymer CSS功能(CSS变量和mixins)时,才需要 <dom-module>
。仅<dom-module>
内<style>
就足够了。