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>
热门推荐
10 朋友新年祝福语大全 简短
11 新年祝福语简短大方兔年
12 搬新家礼物祝福语简短
13 同学见面花束祝福语简短
14 五一假期祝福语幽默简短
15 离职欢送敬酒祝福语简短
16 对学弟的祝福语简短
17 考老师辞职祝福语简短
18 祝福语驱散霉运的话简短