样式
使用 class 样式
数组写法
v-bind:class="['thin',flag?'active':'']"
数组中的值为类名,可以使用三元表达式,在数组中用对象代替三元表达式
v-bind:class = ['thin',{'active':flag}]
在为class用v-bind绑定对象时,对象的属性是类名属性值标识符,属性可以用引号。也可以不用
v-bind:class="[ActiveClass]"
data(){
return {
activeClass:'active'
}
}
对象写法
v-bind:class="{thin:flag}"
使用 style 样式
可以把定义在data中的样式类绑定style
对象写法
v-bind:style="{color:'red',fontWeight:200}"
v-bind:style="thinObject"
var vue = new Vue({
el:,
data:{
thinObject:{font-weight:200,color:'red'},
methods:{}
});
数组写法
可以通过数组绑定style,数组中的元素为样式类
v-bind:style="[thinkObject]"
var vue = new Vue({
el:,
data:{
thinObject:{font-weight:200,color:'red'},
methods:{}
});