aurelia 绑定样式
示例
使用Aurelia绑定到浏览器本机style属性。如果使用字符串插值,则应使用css别名,以便样式在InternetExplorer中起作用。
样式字符串
export class MyViewModel {
constructor() {
this.styleString= 'color: #F2D3D6; background-color: #333';
}
}<template> <div style.bind="styleString"></div> </template>
样式对象
export class MyViewModel {
constructor() {
this.styles= {color: '#F2D3D6', 'background-color': '#333'};
}
}<template> <div style.bind="styles"></div> </template>
字符串插值
与上面的字符串绑定非常相似,这使您可以使用字符串插值来绑定到样式。如果任何值更改,它们将在视图中进行相应更新。
注意:为了与InternetExplorer兼容,我们使用别名css来绑定样式。这样可以确保在InternetExplorer中进行字符串插值。
export class MyViewModel {
color = 'red';
height = 350;
width = 350;
}<template>
<div css="width: ${width}px; height: ${height}px; color:${color}">My Text</div>
</template>
热门推荐
1 敏字的祝福语简短
7 祝福语简短七夕
10 开业经典祝福语简短
11 姨父生日祝福语简短精辟
12 新年祝福语小知识简短
13 宝宝新年祝福语大全简短
14 小伙买车祝福语大全简短
15 长辈体检怎么祝福语简短
16 小清新的祝福语简短
17 哥哥祝福语简短霸气句子
18 朋友节最简短祝福语