【发布时间】:2017-10-09 04:46:40
【问题描述】:
使用ComponentDecorator 的styles 选项/属性的正确方法是什么?将styles 属性与来自存储库stencil-component-starter 的默认my-name 组件一起使用似乎不会影响相应组件的样式,也不会在<head> 中生成类似<style> 标记的东西。 styles 打算如何工作?还是尚未实施?如果目标是避免需要加载单独的 CSS 资源,但为组件提供样式,styles 是正确的选择,还是需要使用其他属性,例如 host?
下面是从 stencil-component-starter]1 生成的示例组件,其中 stylesUrl @Component 属性替换为 styles 属性并设置 font-size 属性。在dev 或build 任务期间不会产生错误。
import { Component, Prop } from '@stencil/core';
@Component({
tag: 'my-name',
styles: `my-name { font-size: 24px; }`
})
export class MyName {
@Prop() first: string;
render() {
return (
<div>
Hello, my name is {this.first}
</div>
);
}
}
ComponentDecorator 定义为:
export interface ComponentOptions {
tag: string;
styleUrl?: string;
styleUrls?: string[] | ModeStyles;
styles?: string;
shadow?: boolean;
host?: HostMeta;
assetsDir?: string;
assetsDirs?: string[];
}
感谢您提供的任何帮助!
【问题讨论】: